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 .
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.
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
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.