Damaged Delusional

3.4

5 votes
Easy-Medium
Problem

“Oh! You meant “Spectacularly ignorant” in a nice way.” -Sherlock

Problem 3

Given a list L, let us denote by F(M) the minimum index P (1-based indexing), such that LCM(L[1],L[2],...,L[P])M. You need to handle T queries. In each query, you'll be given 2 integers N and M. For each query, the list L will be replaced by all the divisors of N. Answer for this query will be F(M).

Input:

First line of input contains a single integer T, denoting the number of test cases. Each of the next T lines contains 2 integers N and M.

Output:

For each query, print an integer F(M) in a new line.

Constraints:

1T106

1MN106

Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?