Find ways an Integer can be expressed as sum of n | PHP program to find number of ways to express a number as sum of n - th powers of numbers . ; Wrapper over checkRecursive ( ) ; Driver Code
< ? php $ res = 0 ; function checkRecursive ( $ num , $ x , $ k , $ n ) { global $ res ; if ( $ x == 0 ) $ res ++ ; $ r = ( int ) floor ( pow ( $ num , 1.0 / $ n ) ) ; for ( $ i = $ k + 1 ; $ i <= $ r ; $ i ++ ) { $ a = $ x - ( int ) pow ( $ i , $ n ) ; if ( $ a >= 0 ) checkRecursive ( $ num , $ x - ( int ) pow ( $ i , $ n ) , $ i , $ n ) ; } return $ res ; } function check ( $ x , $ n ) { return checkRecursive ( $ x , $ x , 0 , $ n ) ; } echo ( check ( 10 , 2 ) ) ; ? >