Find the k-th positive divisor of an integer n in increasing order, or report that it does not exist.
Given two integers and , consider all positive factors (divisors) of arranged in strictly increasing order. Return the factor that appears at position in this ordering.
If has fewer than positive factors, return .
Your goal is to determine the answer efficiently without explicitly relying on a large, repeated search over all numbers up to .
Input Format
- The input consists of two integers and .
- is the number whose positive factors are being queried.
- is the 1-indexed position of the factor to return.
Output Format
- Return a single integer: the -th positive factor of in increasing order.
- If fewer than factors exist, return .
Constraints
- and .
- The answer is 1-indexed.
- Factors are positive integers that divide evenly.
Example 1
Input
n = 12, k = 3
Output
3
Explanation
The positive factors of 12 in increasing order are [1, 2, 3, 4, 6, 12]. The 3rd factor is 3.
Example 2
Input
n = 7, k = 2
Output
7
Explanation
The positive factors of 7 are [1, 7]. The 2nd factor is 7.
Show 1 more example
Example 3
Input
n = 4, k = 4
Output
-1
Explanation
The positive factors of 4 are [1, 2, 4], so there is no 4th factor.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.