Logarithm tricks for Competitive Programming | C # implementation to check if the number is power of K ; Function to count the number of digits in a number ; Logarithm function to calculate value ; Compare to the result1 or result2 both are equal ; Driver Code
using System ; class GFG { static bool isPower ( int N , int K ) { int res1 = ( int ) ( Math . Log ( N ) / Math . Log ( K ) ) ; double res2 = Math . Log ( N ) / Math . Log ( K ) ; return ( res1 == res2 ) ; } public static void Main ( ) { int N = 8 ; int K = 2 ; if ( isPower ( N , K ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }