
The kth Factor of n (medium)
Problem Statement
Given two integers, n and k, return the kth smallest factor of n. If n has fewer factors than k factors, return -1.
A factor of a number is an integer that can divide that number without leaving a remainder.
Examples
-
Example 1:
- Input:
n = 12,k = 5 - Expected Output:
6 - Justification: The factors of 12 are 1, 2, 3, 4, 6, and 12. The fifth smallest factor is 6.
- Input:
-
Example 2:
- Input:
n = 17,k = 2 - Expected Output:
17 - Justification: The factors of 17 are 1 and 17, since 17 is a prime number. The second smallest factor is 17.
- Input:
-
Example 3:
- Input:
n = 10,k = 5 - Expected Output:
-1 - Justification: The factors of 10 are 1, 2, and 5. 10 has only 3 factors, so the answer is
-1.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory