Number of integral solutions for equation x = b * ( sumofdigits ( x ) ^ a ) + c | This function returns the sum of the digits of a number ; This function creates the array of valid numbers ; this computes s ( x ) ^ a ; this gives the result of equation ; checking if the sum same as i ; counter to keep track of numbers ; resultant array ; prints the number ; Driver Code ; calculate which value of x are possible
function getsum ( a ) { let r = 0 , sum = 0 ; while ( a > 0 ) { r = a % 10 ; sum = sum + r ; a = Math . floor ( a / 10 ) ; } return sum ; } function value ( a , b , c ) { let co = 0 , p = 0 ; let no , r = 0 , x = 0 , q = 0 , w = 0 ; let v = [ ] ; for ( let i = 1 ; i < 82 ; i ++ ) { no = Math . pow ( i , a ) ; no = b * no + c ; if ( no > 0 && no < 1000000000 ) { x = getsum ( no ) ; if ( x == i ) { q ++ ; v . push ( no ) ; w ++ ; } } } for ( let i = 0 ; i < v . length ; i ++ ) { document . write ( v [ i ] + " " ) ; } } let a = 2 , b = 2 , c = - 1 ; value ( a , b , c ) ;