Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def kthFactor(self, n: int, k: int) -> int:
- divisors = []
- counterparts = []
- res = -1
- for i in range(1, math.floor(n**0.5) + 1):
- if n % i == 0:
- if i != n // i:
- counterparts.append(n // i)
- divisors.append(i)
- for _ in range(len(counterparts)):
- cp = counterparts.pop()
- divisors.append(cp)
- if k - 1 < len(divisors):
- res = divisors[k-1]
- return res
Advertisement
Add Comment
Please, Sign In to add comment