Check if count of even divisors of N is equal to count of odd divisors | Python3 program for the above approach ; Function to check if count of even and odd divisors are equal ; To store the count of even factors and odd factors ; Loop till [ 1 , sqrt ( N ) ] ; If divisors are equal add only one ; Check for even divisor ; Odd divisor ; Check for both divisor i . e . , i and N / i ; Check if i is odd or even ; Check if N / i is odd or even ; Return true if count of even_div and odd_div are equals ; Given Number ; Function Call
import math NEW_LINE def divisorsSame ( n ) : NEW_LINE INDENT even_div = 0 ; odd_div = 0 ; NEW_LINE for i in range ( 1 , int ( math . sqrt ( n ) ) ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n // i == i ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT even_div += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT odd_div += 1 ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT even_div += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT odd_div += 1 ; NEW_LINE DEDENT if ( n // ( i % 2 ) == 0 ) : NEW_LINE INDENT even_div += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT odd_div += 1 ; NEW_LINE DEDENT DEDENT DEDENT DEDENT return ( even_div == odd_div ) ; NEW_LINE DEDENT N = 6 ; NEW_LINE if ( divisorsSame ( N ) == 0 ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT