Even Perfect Number | Function to check for perfect number ; Find a number close to 2 ^ q - 1 ; Calculate q - 1 ; Condition of perfect number ; Check whether q is prime or not ; Check whether 2 ^ q - 1 is a prime number or not ; Function to check for prime number ; Check whether it is equal to 2 or 3 ; Check if it can be divided by 2 and 3 then it is not prime number ; Check whether the given number be divide by other prime numbers ; Driver Code
function check ( num ) { let root = Math . floor ( Math . sqrt ( num ) ) ; let pow = Math . floor ( Math . log ( root ) / Math . log ( 2 ) ) ; if ( num == Math . floor ( Math . pow ( 2 , pow ) * ( Math . pow ( 2 , pow + 1 ) - 1 ) ) ) { if ( isPrime ( pow + 1 ) ) { if ( isPrime ( Math . floor ( Math . pow ( 2 , pow + 1 ) ) - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ; } else document . write ( " " ) ; } else document . write ( " " ) ; } function isPrime ( n ) { if ( n <= 1 ) return false ; else if ( n == 2 n == 3 ) return true ; else { if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i <= Math . floor ( Math . sqrt ( n ) ) ; i += 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; } return true ; } } let num = 6 ; check ( num ) ;