Count all pairs of divisors of a number N whose sum is coprime with N | Python3 program to count all pairs of divisors such that their sum is coprime with N ; Function to count all valid pairs ; initialize count ; Check if sum of pair and n are coprime ; Return the result ; Driver code
import math as m NEW_LINE def CountPairs ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE i = 1 NEW_LINE while i * i <= n : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT div1 = i NEW_LINE div2 = n // i NEW_LINE sum = div1 + div2 ; NEW_LINE if ( m . gcd ( sum , n ) == 1 ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT return cnt NEW_LINE DEDENT n = 24 NEW_LINE print ( CountPairs ( n ) ) NEW_LINE