Generate K co | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void FindPairs ( int n , int k ) { cout << 1 << " ▁ " << n << endl ; k -- ; for ( long long i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { cout << 1 << " ▁ " << i << endl ; k -- ; if ( k == 0 ) break ; if ( i != n / i ) { cout << 1 << " ▁ " << n / i << endl ; k -- ; } if ( k == 0 ) break ; } } } int main ( ) { int N = 100 ; int K = 5 ; FindPairs ( N , K ) ; return 0 ; }