Function to check if a number can be expressed as a ^ b .
def isPower ( a ) : NEW_LINE INDENT if ( a == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i = 2 NEW_LINE while ( i * i <= a ) : NEW_LINE INDENT val = math . log ( a ) / math . log ( i ) NEW_LINE if ( ( val - int ( val ) ) < 0.00000001 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return False NEW_LINE DEDENT