Find the k | Function to find the k 'th divisor ; initialize vectors v1 and v2 ; store all the divisors in the two vectors accordingly ; reverse the vector v2 to sort it in increasing order ; if k is greater than the size of vectors then no divisor can be possible ; else print the ( k - 1 ) th value of vector ; If K is lying in first vector ; If K is lying in second vector ; Driver code
function findkth ( n , k ) { let v1 = [ ] ; let v2 = [ ] ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . push ( i ) ; if ( i != Math . sqrt ( n ) ) v2 . push ( n / i ) ; } } v2 . reverse ( ) ; if ( k > ( v1 . length + v2 . length ) ) document . write ( " " ) ; else { if ( k <= v1 . length ) document . write ( v1 [ k - 1 ] ) ; else document . write ( v2 [ k - v1 . length - 1 ] ) ; } } let n = 15 , k = 2 ; findkth ( n , k ) ;