Droll Numbers | Python3 program for the above approach ; Function to check droll numbers ; To store sum of even prime factors ; To store sum of odd prime factors ; Add the number of 2 s that divide n in sum_even ; N must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Condition to check droll number ; Given Number N ; Function Call
import math ; NEW_LINE def isDroll ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT sum_even = 0 ; NEW_LINE sum_odd = 0 ; NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT sum_even += 2 ; NEW_LINE n = n // 2 ; NEW_LINE DEDENT for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT sum_odd += i ; NEW_LINE n = n // i ; NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT sum_odd += n ; NEW_LINE DEDENT return sum_even == sum_odd ; NEW_LINE DEDENT N = 72 ; NEW_LINE if ( isDroll ( N ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT