We’re preparing your current view and syncing the latest data.
Given two positive integers n and k, return the kth factor of n. A factor of n is defined as an integer i where n is divisible by i (i.e., n % i == 0). The factors are considered in ascending order. If there are fewer than k factors of n, return -1.
Two integers n and k.
An integer representing the kth factor of n, or -1 if it does not exist.
1 <= k <= n <= 1000
Example 1
Input
12 3
Output
3
Explanation
Factors of 12 sorted are [1, 2, 3, 4, 6, 12]. The 3rd factor is 3.