Find whether a given number is a power of 4 or not | Python3 program to check if given number is power of 4 or not ; 0 is not considered as a power of 4 ; Driver code
import math NEW_LINE def logn ( n , r ) : NEW_LINE INDENT return math . log ( n ) / math . log ( r ) NEW_LINE DEDENT def isPowerOfFour ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT return ( math . floor ( logn ( n , 4 ) ) == math . ceil ( logn ( n , 4 ) ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT test_no = 64 NEW_LINE if ( isPowerOfFour ( test_no ) ) : NEW_LINE INDENT print ( test_no , " ▁ is ▁ a ▁ power ▁ of ▁ 4" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( test_no , " ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) NEW_LINE DEDENT DEDENT