1984.k-th divisor

Time Limit: 1s Memory Limit: 256MB

You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.

Divisor of n is any such natural number, that n can be divided by it without remainder.

Input Format(From the terminal/stdin)

The first line contains two integers n and k (1 \le n \le 1015, 1 \le k \le 109).

Output Format(To the terminal/stdout)

If n has less than k divisors, output -1.

Otherwise, output the k-th smallest divisor of n.

Sample Input 1

Copy
4 2
 · \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
5 3
 · \n

Sample Output 2

Copy
-1
  \n

Sample Input 3

Copy
12 5
  · \n

Sample Output 3

Copy
6
 \n

Hints

In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.

In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

Submit

请先 登录

© 2025 FAQs