Print all numbers that are divisors of N and are co | C ++ program for the above approach ; Function to print all numbers that are divisors of N and are co - prime with the quotient of their division ; Iterate upto square root of N ; If divisors are equal and gcd is 1 , then print only one of them ; Otherwise print both ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printUnitaryDivisors ( int n ) { for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i && __gcd ( i , n / i ) == 1 ) { printf ( " % d ▁ " , i ) ; } else { if ( __gcd ( i , n / i ) == 1 ) { printf ( " % d ▁ % d ▁ " , i , n / i ) ; } } } } } int main ( ) { int N = 12 ; printUnitaryDivisors ( N ) ; return 0 ; }