Representation of a number in powers of other | PHP 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
< ? php function asPowerSum ( $ w , $ m ) { while ( $ m ) { 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 ) ; } $ w = 3 ; $ m = 7 ; if ( asPowerSum ( $ w , $ m ) ) echo " Yes STRNEWLINE " ; else echo " No STRNEWLINE " ; ? >