Generate K co | Java implementation of the above approach ; Function prints the required pairs ; First co - prime pair ; As a pair ( 1 n ) has already been Printed ; If i is a factor of N ; Since ( i , i ) won 't form  a coprime pair ; Driver Code
import java . util . * ; class GFG { static void FindPairs ( int n , int k ) { System . out . print ( 1 + " ▁ " + n + "NEW_LINE"); k -- ; for ( long i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { System . out . print ( 1 + " ▁ " + i + "NEW_LINE"); k -- ; if ( k == 0 ) break ; if ( i != n / i ) { System . out . print ( 1 + " ▁ " + n / i + "NEW_LINE"); k -- ; } if ( k == 0 ) break ; } } } public static void main ( String [ ] args ) { int N = 100 ; int K = 5 ; FindPairs ( N , K ) ; } }