Leetcode 1585 Solution

This article provides solution to leetcode question 1585 (the-kth-factor-of-n)

https://leetcode.com/problems/the-kth-factor-of-n

Solution

class Solution:
    def kthFactor(self, n: int, k: int) -> int:
        i = 1
        cnt = 0
        while i <= n:
            if n % i == 0:
                cnt += 1

                if cnt == k:
                    return i
            i += 1
        return -1