Check if a number can be expressed as power | Set 2 ( Using Log ) | PHP program to find if a number can be expressed as x raised to power y . ; Find Log n in different bases and check if the value is an integer ; Driver code
< ? php function isPower ( $ n ) { for ( $ x = 2 ; $ x <= sqrt ( $ n ) ; $ x ++ ) { $ f = log ( $ n ) / log ( $ x ) ; if ( ( $ f - ( int ) $ f ) == 0.0 ) return true ; } return false ; } for ( $ i = 2 ; $ i < 100 ; $ i ++ ) if ( isPower ( ( int ) $ i ) ) echo $ i . " " ; ? >