#25 Solve the recommended problem. ABC105-C
** Thoughts ** First, let's consider a method for converting to a normal binary number. Convert decimal numbers to binary numbers with this. Make this a -2 base version. The change is that the remainder is a natural number, so you have to adjust the remainder well. When it is divisible by -2, there is not much left, so n // 2 as it is. If there is a remainder, you can calculate it well by dividing it by n-1 and then -2. If you append with this calculation method, the order of the answers will be reversed, so it will be reversed. After that, just join to str.
n = int(input())
if n == 0:
print(0)
quit()
base = []
while n != 1:
if n % -2 == 0:
base.append('0')
n //= -2
else:
base.append('1')
n -= 1
n //= -2
base.append('1') #Don't forget to do one at the end
base.reverse()
ans = ''.join(base)
print(ans)
pleasant. see you
Recommended Posts