Perfect Digital Invariants number | Function to calculate x raised to the power y ; Function to check whether the given number is Perfect Digital Invariant number or not ; For each digit in temp ; If satisfies Perfect Digital Invariant condition ; If sum exceeds n , then not possible ; Given Number N ; Function Call
function power ( x , y ) { if ( y == 0 ) { return 1 ; } if ( y % 2 == 0 ) { return ( power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ) ; } return ( x * power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ) ; } function isPerfectDigitalInvariant ( x ) { for ( var fixed_power = 1 ; ; fixed_power ++ ) { var temp = x , sum = 0 ; while ( temp ) { var r = temp % 10 ; sum += power ( r , fixed_power ) ; temp = Math . floor ( temp / 10 ) ; } if ( sum == x ) { return true ; } if ( sum > x ) { return false ; } } } var N = 4150 ; if ( isPerfectDigitalInvariant ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;