Find two proper factors of N such that their sum is coprime with N | Python 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
import math NEW_LINE def printFactors ( n ) : NEW_LINE INDENT for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT d1 = i NEW_LINE d2 = n NEW_LINE while ( d2 % d1 == 0 ) : NEW_LINE INDENT d2 = d2 // d1 NEW_LINE DEDENT if ( d1 > 1 and d2 > 1 ) : NEW_LINE INDENT print ( d1 , d2 , sep = " , ▁ " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT N = 10 NEW_LINE printFactors ( N ) NEW_LINE