var kthFactor = function(n, k) {
let set = new Set()
let left = 1
let right = n
while (left <= right) {
if (n % left === 0) {
right = n/left
set.add(left).add(right)
}
left++
}
set = Array.from(set).sort((a, b) => a - b)
return set[k - 1] ? set[k - 1] : -1
};