Find two proper factors of N such that their sum is coprime with N | C ++ Program for the above approach ; Function to find two proper factors of N such that their sum is coprime with N ; Find factors in sorted order ; Find largest value of d2 such that d1 and d2 are co - prime ; Check if d1 and d2 are proper factors of N ; Print answer ; No such factors exist ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printFactors ( int n ) { for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { int d1 = i , d2 = n ; while ( d2 % d1 == 0 ) { d2 = d2 / d1 ; } if ( d1 > 1 && d2 > 1 ) { cout << d1 << " , ▁ " << d2 ; return ; } } } cout << -1 ; } int main ( ) { int N = 10 ; printFactors ( N ) ; return 0 ; }