Representation of a number in powers of other | Javascript program to check if m can be represented as powers of w . ; break ; None of 3 worked . ; If m is not zero means , it can 't be  represented in terms of powers of w. ; Driver code
function asPowerSum ( w , m ) { while ( m > 0 ) { if ( ( m - 1 ) % w == 0 ) m = ( m - 1 ) / w ; else if ( ( m + 1 ) % w == 0 ) m = ( m + 1 ) / w ; else if ( m % w == 0 ) m = m / w ; else } return ( m == 0 ) ; } let w = 3 , m = 7 ; if ( asPowerSum ( w , m ) ) document . write ( " " ) ; else document . write ( " " ) ;