Python/백준

[2089] -2진수

류경혜 2022. 8. 15. 02:00

n = int(input())
if not n:
    print('0')
    exit()
result = ''
while n:
    if n % (-2):
        result = '1' + result
        n = n//(-2) + 1
    else:
        result = '0' + result
        n //= -2
print(result)