text: Coprime divisors of a number | Function which finds the required pair of divisors of N ; We iterate upto sqrt ( N ) as we can find all the divisors of N in this time ; If x is a divisor of N keep dividing as long as possible ; We have found a required pair ; No such pair of divisors of N was found , hence print - 1 ; Sample example 1 ; Sample example 2
code: function findCoprimePair ( N ) { for ( let x = 2 ; x <= Math . sqrt ( N ) ; x ++ ) { if ( N % x == 0 ) { while ( N % x == 0 ) { N = Math . floor ( N / x ) ; } if ( N > 1 ) { document . write ( x + " " + N + " " ) ; return ; } } } document . write ( - 1 + " " ) ; } let N = 45 ; findCoprimePair ( N ) ; N = 25 ; findCoprimePair ( N ) ;