Check if a number can be expressed as power | Set 2 ( Using Log ) | C # 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
using System ; class GFG { static bool isPower ( int n ) { for ( int x = 2 ; x <= ( int ) Math . Sqrt ( n ) ; x ++ ) { float f = ( float ) Math . Log ( n ) / ( float ) Math . Log ( x ) ; if ( ( f - ( int ) f ) == 0.0 ) return true ; } return false ; } public static void Main ( ) { for ( int i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) Console . Write ( i + " ▁ " ) ; } }