Check if a number can be expressed as x ^ y ( x raised to power y ) | C # program to check if a given number can be expressed as power ; Returns true if n can be written as x ^ y ; Driver code
using System ; class GFG { static bool isPower ( int n ) { double p ; if ( n <= 1 ) { return true ; } for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { p = Math . Log ( n ) / Math . Log ( i ) ; if ( ( Math . Ceiling ( p ) == Math . Floor ( p ) ) && p > 1 ) { return true ; } } return false ; } static public void Main ( ) { for ( int i = 2 ; i < 100 ; i ++ ) { if ( isPower ( i ) ) Console . Write ( i + " ▁ " ) ; } } }