Droll Numbers | 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 polet . So we can skip one element ( Note i = i + 2 ) ; While i divides n , prlet 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
function isDroll ( n ) { if ( n == 1 ) return false ; let sum_even = 0 ; let sum_odd = 0 ; while ( n % 2 == 0 ) { sum_even += 2 ; n = n / 2 ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { sum_odd += i ; n = n / i ; } } if ( n > 2 ) sum_odd += n ; return sum_even == sum_odd ; } let n = 72 ; if ( isDroll ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;