You are given two positive integers n and k. A factor of n is an integer i with n % i == 0. List all factors of n in ascending order and return the kth one, or -1 if n has fewer than k factors.
You are given two positive integers n and k. A factor of n is an integer i with n % i == 0. List all factors of n in ascending order and return the kth one, or -1 if n has fewer than k factors.
Example 1:
Input: {"n":12,"k":3}
Output: 3
Constraints:
1≤k≤n≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":12,"k":3}
Find the 3rd smallest factor of 12. Factors come in pairs d × 12/d, so only d up to √12 ≈ 3 needs testing.