Coprime divisors of a number | Python3 program to find two coprime divisors of a given number such that both are greater than 1 ; 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
import math NEW_LINE def findCoprimePair ( N ) : NEW_LINE INDENT for x in range ( 2 , int ( math . sqrt ( N ) ) + 1 ) : NEW_LINE INDENT if ( N % x == 0 ) : NEW_LINE INDENT while ( N % x == 0 ) : NEW_LINE INDENT N //= x NEW_LINE DEDENT if ( N > 1 ) : NEW_LINE INDENT print ( x , N ) NEW_LINE return ; NEW_LINE DEDENT DEDENT DEDENT print ( " - 1" ) NEW_LINE DEDENT N = 45 NEW_LINE findCoprimePair ( N ) NEW_LINE N = 25 NEW_LINE findCoprimePair ( N ) NEW_LINE