Print all numbers that are divisors of N and are co | python 3 program for the above approach ; Function to print all numbers that are divisors of N and are co - prime with the quotient of their division ; Iterate upto square root of N ; If divisors are equal and gcd is 1 , then print only one of them ; Otherwise print both ; Driver Code
from math import sqrt , gcd NEW_LINE def printUnitaryDivisors ( n ) : NEW_LINE INDENT for i in range ( 1 , int ( sqrt ( n ) ) + 1 , 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n // i == i and gcd ( i , n // i ) == 1 ) : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( gcd ( i , n // i ) == 1 ) : NEW_LINE INDENT print ( i , n // i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 12 NEW_LINE printUnitaryDivisors ( N ) NEW_LINE DEDENT