Count of numbers whose sum of increasing powers of digits is equal to the number itself | Function to return the count of digits of n ; Function to return the sum of increasing powers of N ; To store the required answer ; Count of digits in n which will be the power of the last digit ; While there are digits left ; Get the last digit ; Add the last digit after raising it to the required power ; Decrement the power for the previous digit ; Remove the last digit ; Function to return the count of integers which satisfy the given conditions ; If current element satisfies the given condition ; Driver code
function countDigits ( n ) { let cnt = 0 ; while ( n > 0 ) { cnt ++ ; n = Math . floor ( n / 10 ) ; } return cnt ; } function digitPowSum ( n ) { let sum = 0 ; let pw = countDigits ( n ) ; while ( n > 0 ) { let d = n % 10 ; sum += Math . pow ( d , pw ) ; pw -- ; n = Math . floor ( n / 10 ) ; } return sum ; } function countNum ( n ) { let count = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { if ( i == digitPowSum ( i ) ) { count ++ ; } } return count ; } let n = 200 ; document . write ( countNum ( n ) ) ;