The kth Factor of n
You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.
Consider a list of all factors of n sorted in ascending order. Return the k^th factor in this list, or return -1 if n has less than k factors.
Follow up: Could you solve this problem in less than O(n) complexity?
Example 1
Input
n = 12, k = 3Output
3Factors list is [1, 2, 3, 4, 6, 12], so the 3^rd factor is 3.
Example 2
Input
n = 7, k = 2Output
7Factors list is [1, 7], so the 2^nd factor is 7.
Constraints
- 1 <= k <= n <= 1000