<s> """<STR_LIT>""" <EOL> from decimal import * <EOL> __author__ = '<STR_LIT>' <EOL> class Solution : <EOL> def binaryRepresentation ( self , n ) : <EOL> """<STR_LIT>""" <EOL> dec_part = "<STR_LIT>" <EOL> if "<STR_LIT:.>" in n : <EOL> int_part , dec_part = n . split ( "<STR_LIT:.>" ) <EOL> getcontext ( ) . prec = len ( dec_part ) + <NUM_LIT:1> <EOL> dec_part = "<STR_LIT:.>" + dec_part <EOL> if not self . is_representable ( Decimal ( dec_part ) ) : <EOL> return "<STR_LIT>" <EOL> else : <EOL> int_part = n <EOL> a = self . natural_num_to_bin ( int ( int_part ) ) <EOL> b = self . fraction_to_bin ( Decimal ( dec_part ) ) <EOL> if a == "<STR_LIT>" : <EOL> a = "<STR_LIT:0>" <EOL> if b == "<STR_LIT>" : <EOL> return a <EOL> else : <EOL> return a + "<STR_LIT:.>" + b <EOL> @ staticmethod <EOL> def natural_num_to_bin ( n ) : <EOL> """<STR_LIT>""" <EOL> sb = [ ] <EOL> while n > <NUM_LIT:0> : <EOL> sb . append ( n & <NUM_LIT:1> ) <EOL> n >>= <NUM_LIT:1> <EOL> return "<STR_LIT>" . join ( map ( str , reversed ( sb ) ) ) <EOL> @ staticmethod <EOL> def fraction_to_bin ( n ) : <EOL> """<STR_LIT>""" <EOL> sb = [ ] <EOL> while n > <NUM_LIT:0> : <EOL> if len ( sb ) > <NUM_LIT:32> : <EOL> return "<STR_LIT>" <EOL> n *= Decimal ( <NUM_LIT:2> ) <EOL> cur = int ( n ) <EOL> sb . append ( cur ) <EOL> n -= Decimal ( cur ) <EOL> return "<STR_LIT>" . join ( map ( str , sb ) ) <EOL> @ staticmethod <EOL> def is_representable ( frac ) : <EOL> """<STR_LIT>""" <EOL> while True : <EOL> temp = str ( frac ) . rstrip ( "<STR_LIT:0>" ) <EOL> if temp . endswith ( "<STR_LIT:.>" ) : <EOL> return True <EOL> if not temp . endswith ( "<STR_LIT:5>" ) : <EOL> return False <EOL> frac *= Decimal ( <NUM_LIT:2> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> assert Solution ( ) . binaryRepresentation ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert Solution ( ) . binaryRepresentation ( "<STR_LIT>" ) == "<STR_LIT>" <EOL> assert Solution ( ) . binaryRepresentation ( "<STR_LIT>" ) == "<STR_LIT>" </s>
