Find the k | Java program to find the K - th smallest factor ; 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
import java . util . * ; class GFG { static void findkth ( int n , int k ) { Vector < Integer > v1 = new Vector < Integer > ( ) ; Vector < Integer > v2 = new Vector < Integer > ( ) ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . add ( i ) ; if ( i != Math . sqrt ( n ) ) v2 . add ( n / i ) ; } } Collections . reverse ( v2 ) ; if ( k > ( v1 . size ( ) + v2 . size ( ) ) ) System . out . print ( " Doesn ' t ▁ Exist " ) ; else { if ( k <= v1 . size ( ) ) System . out . print ( v1 . get ( k - 1 ) ) ; else System . out . print ( v2 . get ( k - v1 . size ( ) - 1 ) ) ; } } public static void main ( String [ ] args ) { int n = 15 , k = 2 ; findkth ( n , k ) ; } }