~์ค๋ฒ 2~
[ํด๊ฒฐ ํฌ์ธํธ]
1. 2์ง์์ฒ๋ผ -2์ ๋๋จธ์ง๋ฅผ ์ ์ฅํ์ฌ ์ถ๋ ฅ
2. ๋๋จธ์ง๊ฐ 0์ด ์๋ ๋ +1
[์ต์ข ์ฝ๋]
n = int(input())
result = []
if n == 0: # ์
๋ ฅ ๊ฐ์ด 0์ผ ๋
print(0)
else:
while n != 0:
temp = n % -2
result.append(-temp)
n //= -2
if temp: # ๋๋จธ์ง๊ฐ 0์ด ์๋๋ผ๋ฉด
n += 1
for r in reversed(result):
print(r, end="")
์์ ์ ๋ ฅ์ฒ๋ผ -13์ด ๋ค์ด์๋ค๊ณ ์๊ฐํด๋ณด์
REFERENCE
https://suri78.tistory.com/119