Kth Positive Factor in Ascending Order
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Return the kth smallest positive divisor of n,or -1 if n has fewer than k positive divisors.
```cpp
class Solution {
public:
int kthFactor(int n, int k);
};
```
### Examples
**Example 1:**
```text
Input: n = 18, k = 4
Output: 6
Explanation: The factors are1,2,3,6,9,18.
```
**Example 2:**
```text
Input: n = 9, k = 4
Output: -1
Explanation: Its factors are only1,3,9; the square-root factor3 is counted once.
```
### Constraints
- `1 <= k <= n <= 1000`.
### Contract considerations
Only positive factors are included.
```hint Read the boundary condition
Count only positive factors, in ascending order and without duplication. Check perfect squares and a requested rank beyond the factor count.
```
### Boundary reminders
Only positive factors are included.
### Optional extensions
Can you solve the problem in less than O(n) time?
Overview: Kth Positive Factor in Ascending Order. Return the kth smallest positive divisor of n,or-1 if n has fewer than k positive divisors.