Find two proper factors of N such that their sum is coprime with N | 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
function printFactors ( n ) { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { let d1 = i , d2 = n ; while ( d2 % d1 == 0 ) { d2 = Math . floor ( d2 / d1 ) ; } if ( d1 > 1 && d2 > 1 ) { document . write ( d1 + " " + d2 ) ; return ; } } } document . write ( - 1 ) ; } let N = 10 ; printFactors ( N ) ;