Thabit number | Utility function to Check power of two ; function to check if the given number is Thabit Number ; Add 1 to the number ; Divide the number by 3 ; Check if the given number is power of 2 ; Driver Program ; Check if number is thabit number
def isPowerOfTwo ( n ) : NEW_LINE INDENT return ( n and ( not ( n & ( n - 1 ) ) ) ) NEW_LINE DEDENT def isThabitNumber ( n ) : NEW_LINE INDENT n = n + 1 ; NEW_LINE if ( n % 3 == 0 ) : NEW_LINE INDENT n = n // 3 ; NEW_LINE DEDENT else : NEW_LINE return False NEW_LINE if ( isPowerOfTwo ( n ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT n = 47 NEW_LINE if ( isThabitNumber ( n ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT