Problem:


Score : 300 points

Problem Statement

Given an integer N, find the base -2 representation of N.

Here, S is the base -2 representation of N when the following are all satisfied:

S is a string consisting of 0 and 1.

Unless S = 0, the initial character of S is 1.

Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N.

It can be proved that, for any integer M, the base -2 representation of M is uniquely determined.

Constraints

Every value in input is integer.

-10^9 \leq N \leq 10^9

Input

Input is given from Standard Input in the following format:

N

Output

Print the base -2 representation of N.

Sample Input 1

-9

Sample Output 1

1011

As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.

Sample Input 2

123456789

Sample Output 2

11000101011001101110100010101

Sample Input 3

0

Sample Output 3

0



Sample input:
-9


Sample output:
1011

Submission status: Accepted

Solution code:
LOWER, UPPER = range(2)
MAX_DIGIT = 33
n = 0
bounds = [0] * MAX_DIGIT
for digit in range(MAX_DIGIT):
    n = (n << 1) | (digit & 1)
    bounds[digit] = [-(n >> (digit & 1)), n >> (not (digit & 1))]

N = int(input())

answer = 0
n = (1 << digit) * (1 if MAX_DIGIT & 1 else -1)

while digit:
    answer <<= 1
    n = (-1) * n >> 1
    if bounds[digit][LOWER] <= N < bounds[digit - 1][LOWER] or \
        bounds[digit - 1][UPPER] < N <= bounds[digit][UPPER]:
        answer |= 1
        N -= n
    digit -= 1

print(format(answer, "b"))

Submission status: Accepted

Solution code:
#105_C
N=int(input())
def X(N):
    x=N%2
    N_new=(N-x)//(-2)
    if N_new==0:
        return x
    return X(N_new)*10+x
print(X(N))

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
  print(0)
else:
  ans = ""
  now = 0
  while n:
    r = n % (2**(now+1))
    if r:
      ans = "1" + ans
      n -= (-2)**now
    else:
      ans = "0" + ans
    now += 1
  print(ans)

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    N=int(input())
    if N==0:
        print(0)
    else:
        ans=[]
        while N:
            ans.append(str(N%2))
            N=-(N//2)
        ans.reverse()
        print("".join(ans))

Submission status: Accepted

Solution code:
n = int(input())
r = 100
s = [0] * (r+1)
w = 0
for i in range(r+1):
    mod = 2 ** (i+1)
    if n % mod == w % mod:
        s[i] = 0
    else:
        s[i] = 1
    w += s[i] * (-2)**i
    if w == n:
        break

print(int("".join(map(str, reversed(s)))))

Submission status: Accepted

Solution code:
n=int(input()); b=''
while n: b=str(n%2)+b; n=-(n//2)
print(b if b else 0)

Submission status: Accepted

Solution code:
n = int(input())
b = ''
while n:
  b = str(n%2)+b
  n = -(n//2)
print(b if b else 0)

Submission status: Accepted

Solution code:
n=int(input())
t=1
b=''
for i in range(len(bin(n))):
  if n%(2*t): b='1'+b; n-=t
  else: b='0'+b
  t*=-2
print(int(b))

Submission status: Accepted

Solution code:
from math import ceil, log

def main():
    n = int(input())
    if n == 0:
        print(0)
        return
    k = 2 * int(log(3 * n, 4)) + 1 if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4))
    s = [0] * k
    while n:
        k = 2 * int(log(3 * n, 4)) if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4)) - 1
        s[k] = 1
        n -= (-2)**k
    print(*s[::-1], sep="")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()

mi = 0; ma = 1
li = [[0,1]]
for i in range(1,10**6):
    tmp = (-2) ** i
    if tmp < 0: mi += tmp
    else: ma += tmp
    li.append([mi,ma])
    if mi <= n <= ma:
        c = i+1
        break
# print(li)
res = []
for i in range(c)[::-1]:
    tmp = n - (-2) ** i
    if i != 0:
        nexl,nexr = li[i-1]
        if nexl <= tmp <= nexr:
            res.append('1')
            n = tmp
        else: res.append('0')
        continue
    res.append('1') if n else res.append('0')
ans = int("".join(res))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
while n != 0:
    r = n % (-2)
    if r < 0:
        r += 2
    n = int((n - r) / (-2))
    ans += str(r)
if ans == "":
    print(0)
else:
    print(ans[::-1])

Submission status: Accepted

Solution code:
N=int(input())
S = ""
while N != 0:
  if N%2==0:
    S = "0" + S
  else:
    S = "1" + S
    N -= 1
  N /= -2
if S == "": S = "0"
print(S)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
def num(n):
    if n == 0:
        return ""
    if n%2 == 0:
        return num(n//(-2)) + "0"
    else:
        return num((n-1)//(-2)) + "1"
if n == 0:
    print(0)
    exit()
print(num(n))

Submission status: Accepted

Solution code:
n = int(input())
s = []
i = 1
m = (n%2)
s.append(n%2)
while 1:
    if m == n:
        break
    if n%(2**(i+1)) == m or n%(2**(i+1))-2**(i+1) == m:
        s.append(0)
    else:
        s.append(1)
        m += (-2)**i
    i += 1

print(''.join(map(str, s[::-1])))

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
    print(0)
    exit()
flag = True
ans_str = ''
while True:
    if n == 1:
        ans_str = '1' + ans_str
        print(int(ans_str))
        exit()
    if n < 0 and (-n)%2 == 1:
        ans_str = '1' + ans_str
        n = -(n-1)//2
    elif n < 0 and (-n)%2 == 0:
        ans_str = '0' + ans_str
        n = -n//2
    elif n > 0 and n%2 ==1:
        ans_str = '1' + ans_str
        n = -(n//2)
    elif n > 0 and n%2 ==0:
        ans_str = '0' + ans_str
        n = -(n//2)

Submission status: Accepted

Solution code:
n = int(input())
mx=50

n2_lis=[1]
for i in range(1,mx):
    n2_lis.append(n2_lis[i-1]*(-2))

sum_p=[0]
sum_m=[0]
sp=0
sm=0
for num in n2_lis:
    if num > 0:
        sp+=num
    else:
        sm+=num
    sum_p.append(sp)
    sum_m.append(sm)

rg=[]
for i in range(mx):
    rg1=n2_lis[i] + sum_p[i]
    rg2=n2_lis[i] + sum_m[i]
    rg.append([min(rg1,rg2),max(rg1,rg2)])

ans=[]
for i in reversed(range(0,mx)):
    if rg[i][0] <= n and n <= rg[i][1]:
        ans.append(1)
        n-=n2_lis[i]
    else:
        ans.append(0)
ans = ''.join([str(n) for n in ans])
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())

res = ""
while n:
	#print(n, n%2, -(n-1)//2)
	res += "1" if n%2 else "0"
	n = -(n-1)//2
	
print(res[::-1] or "0")

Submission status: Accepted

Solution code:
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N = SI()
    
    if N == 0:
        print(0)
    else:
        ret = ''
        cursor = 1
        devide = 2
        while N != 0:
            if N % devide == 0:
                ret = '0' + ret
            else:
                ret = '1' + ret
                N -= cursor
            cursor *= -2
            devide *= 2
        
        print(ret)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        if n == 0:
            return 0
        digits = []
        i = 0
        base = 1
        while n != 0:
            if n % (base*2) == 0:
                digits.append("0")
            else:
                digits.append("1")
                n -= base
            i += 1
            base *= -2
        return "".join(digits[::-1])

    print(to_bin(N))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

ans = []
while True:
    if n % 2 == 1:
        ans.append('1')
        n -= 1
    else:
        ans.append('0')
    n = n // (-2)
    if n == 0:
        break

print(''.join(ans[::-1]))

Submission status: Accepted

Solution code:
s=int(input())
x=s
list=[]
for i in range(1000000000000000000):
    y=x%(-2)
    if y == -1:
        x = (x-1)//(-2)
        y = 1
    else:
        x=x//(-2)
    list.insert(0, y)
    if x == 0:
        print(*list, sep="")
        break

Submission status: Accepted

Solution code:
def main():
    target_number = int(input())
    answer = ""
    if target_number == 0:
        answer = "0"
    else:
        while abs(target_number) > 0:
            if target_number % 2:
                answer = "1" + answer
                target_number = (target_number - 1) // -2
            else:
                answer = "0" + answer
                target_number = target_number // -2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    i = 0
    if not N:
        print(0)
        return
    ans = ""
    while N:
        if N>>i&1:
            ans += "1"
            N -= pow(-1,i%2==1) * 1<<i
        else:
            ans += "0"
        i+=1
    
    print(ans[::-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
ans=''

if N==0:
    print('0')
    exit()

while N!=0:
    Nmod=N%(-2)
    ans+=str(abs(Nmod))
    
    if Nmod==-1:
        N=N//(-2)+1
    else:
        N=N//(-2)

print(''.join(list(reversed(ans))))

Submission status: Accepted

Solution code:
N=int(input())

ans=[]
NN=10**7

for _ in range(NN):
    if (abs(N))%2==1:
        ans.append("1")
        N-=1
    else:
        ans.append("0")
    if N==0:
        break
    N=(abs(N)//2)*-1*(N//abs(N))
    
print(''.join(map(str, ans[::-1])))

Submission status: Accepted

Solution code:
import math
import sys

N = int(input())

ans = []
if N == 0:
  print(0)
  sys.exit()

while(N != 0):
  m = N % (-2)
  if m == -1:
    m = 1
  ans.insert(0, str(m))
  N = math.ceil(N / (-2))

print("".join(ans))

Submission status: Accepted

Solution code:
def minus2base(n):
    if n==0:
        return '0'
    elif n==1:
        return '1'
    elif n>1:
        k=1
        i=1
        a=n
        while a-k>=0:
            a=a-k
            if a==0:
                break
            k=4*k
            i=i+1
        if n-k>0:
            A='10'
            l=1
            j=1
            a=n-k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
        elif n-k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A
        else:
            A='1'
            l=2
            j=1
            a=n-k
            while 0>a+l:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
    else:
        k=2
        i=1
        a=n
        while 0>a+k:
            a=a+k
            k=4*k
            i=i+1
        if n+k<0:
            A='10'
            l=2
            j=1
            a=n+k
            while a+l<0:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
        elif n+k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A[:-1]
        else:
            A='1'
            l=1
            j=1
            a=n+k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=4*l
                j=j+1
            m=i-j
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
N=int(input())
print(minus2base(N))

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
ans = ""
while N:
    ans = str(N&1)+ans
    N = -(N>>1)
print(ans if ans else 0)

Submission status: Accepted

Solution code:
import math
import sys
n=int(input())
ans=[]
syo=n
if n==0:
    print(0)
    sys.exit(0)
while syo!=0:
    zan=syo%-2
    if zan==-1:
        zan=1
    ans.insert(0,zan)
    syo=math.ceil(syo/-2)
for i in range(len(ans)):
    print(ans[i],end="")

Submission status: Accepted

Solution code:
N = int(input())
S = ""
#素因数分解
while N:
    if N%(-2) == 0:
        S = "0"+S
    else:
        S = "1"+S
        #余りとなった部分を引く
        N -= 1
    N = N/(-2)

if S=="":
    S="0"

print(S)

Submission status: Accepted

Solution code:
n = int(input())
if 0<= n < 2:
    print(n)
    exit()

bit = 2
i = 0
l,r = 0,1
rang = [(0,1)]
while n < l or r < n:
    i += 1
    bit *= -2
    if i % 2:
        l = bit+1 + r
    else:
        r = bit-1 + l
    rang.append((l,r))
    # print(l,r,bit, i)

ans = []
# print(rang)
bit //= 2
# print(bit)
while i >= 0:
    t = n - bit
    # print(t, rang[i])
    if rang[i][0] <= t <= rang[i][1]:
        ans.append('1')
        n = t
    else:
        ans.append('0')
    i -= 1
    bit //= -2
print(''.join(ans))

Submission status: Accepted

Solution code:
n=int(input())
s=""
while n:
    s=str(n&1)+s
    n=-(n>>1)
print(s if s else 0)

Submission status: Accepted

Solution code:
n=int(input())
deg=[0]*40
if n>=0:
    for i in range(32):
        if n>>i&1:
            if i%2==0:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==0:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
else:
    n*=-1
    for i in range(32):
        if n>>i&1:
            if i%2==1:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==1:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
deg.reverse()
l=39
for i in range(40):
    if deg[i]==1:
        l=i
        break
print(*deg[l:],sep="")

Submission status: Accepted

Solution code:
N = int(input())

N = -N

if N == 0:
  print(0)
  exit()
  
t = []
while N != 0:
  s = N % -2
  if s == 0:
    t.append(0)
  else:
    t.append(1)
    
  N //= -2
  
t = list(reversed(t))
print(''.join(map(str, t)))

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
while 1:
    if n % (-2):
        ans += '1'
    else:
        ans += '0'
    n = (n-1) // (-2)
    if n == 0:
        break
ans = ans[::-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
  print('0')
  exit()
s = ''
while n != 0:
    s = str(n%2)+s
    n //= 2
    n *= -1
print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N = cin.int()

ans = ""
while(N != 0):
    q = N % 2
    p = (N - q) // (-2)
    ans += str(q)
    N = p
if ans == "":
    ans += "0"
print(ans[::-1])

Submission status: Accepted

Solution code:
n = int(input())

ans = ''

if n == 0:
    print('0')

while n != 0:
    r = n % 2 

    if r < 0:
        r = r + 2
    
    n = (n-r) / (-2)

    ans = ans + str(int(r))

ans = list(ans)    
ans.reverse()
print(''.join(ans))

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
base = 1
n = -n
while (n != 0):
   p = abs(n % (-2))
   n = (n + p) // (-2)
   ans += p * base
   base *= 10

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n==0:
    print('0')
    exit()
ans = ''
while n != 0:
    if n%(-2) == 0:
        ans = '0' + ans
        n /= -2
    else:
        ans = '1' + ans
        n = (n-1)/(-2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
n = -n

if n == 0:
    print(0)
    exit()
t = []
while n != 0:
    s = n%-2
    if s == 0:
        t.append(0)
    else:
        t.append(1)
    n //= -2

t = t[::-1]
for i in t:
    print(i, end='')

Submission status: Accepted

Solution code:
n=int(input())
r=''
if n==0:
	print('0')
else:
	while n!=0:
		if n>=0:
			r+=str(n%2)
			n=-(n//2)
		else:
			r+=str(-(-n%-2))
			n=-(-n//-2)
print(r[::-1])

Submission status: Accepted

Solution code:
# -2進数の場合
N=int(input())
if N==0:
  print(0)
  exit(0)
d=-2
ans=[]
while N!=0:
    r=N%(d)
    if r<0:
        r+=2
    N=(N-r)//(d)
    ans.append(str(r))
    
print("".join(ans[::-1]))

Submission status: Accepted

Solution code:
N = int(input())

def dec_to_n(N, n):
    if N == 0:
        return "0"
    digits = []
    base = 1
    while N != 0:
        if N % (base * n) == 0:
            digits.append('0')
        else:
            digits.append('1')
            N -= base
        base *= n
    return "".join(digits[::-1])

print(dec_to_n(N, -2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())

def dec_to_n(N, n):
    if N == 0:
        return "0"
    digits = []
    i = 0
    base = 1
    while N != 0:
        if N % (base * n) == 0:
            digits.append('0')
        else:
            digits.append('1')
            N -= base
        i += 1
        base *= n
    return "".join(digits[::-1])

print(dec_to_n(N, -2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
i = 0
ans = []
if N == 0:
    print(0)
    sys.exit()
while N != 0:
    i += 1
    if N % 2 == 0:
        N //= 2
        ans.append("0")
    else:
        if i % 2 == 1:
            N -= 1
            N //= 2
            ans.append("1")
        else:
            N += 1
            N //= 2
            ans.append("1")
print("".join(ans[::-1]))

Submission status: Accepted

Solution code:
n = int(input())
st = ""

while n != 0:
    r = n % 2
    if r < 0:
        r += 2
    n = int((n - r) / (-2))
    st += str(r)

st = st[::-1]

if st == "":
    st = "0"
print(st)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    if n == 0:
        print(0)
        return
    ans = ''
    c = 0
    while n != 1:
        c += 1
        s, a = divmod(n, -2)
        # print(s, a)
        if a == -1:
            s += 1
            a = 1
        ans += str(a)
        n = s
    ans += '1'
    print(''.join(reversed(ans)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import log2

def main():
    N = int(input())
    if N == 0:
        print(0)
        return
    Ans = []
    while N !=  0:
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = []
if N == 0:
  a.append("0")
while N != 0:
  a.append(str(N % 2))
  N = -(N // 2)
print("".join(reversed(a)))

Submission status: Accepted

Solution code:
n = int(input())

if n != 0:
	ans = []
	while n != 0:
		ans.append(abs(n % -2))

		n += n % -2
		n /= -2
		n = int(n)

	print(''.join([str(i) for i in reversed(ans)]))
else:
	print(0)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
if N==0:
  print(0)
else:
  while(abs(N)!=0):
    a=N%2
    A.append(a)
    N=(N-a)//(-2)
B=A[::-1]
print(*B,sep='')

Submission status: Accepted

Solution code:
import math
N = int(input())
if N == 0:
    print(0)
    exit()
ans = ""
while N != 1:
    if N % 2 == 0:
        N //= (-2)
        ans = "0" + ans
    else:
        if N > 0:
            N //= (-2)
            N += 1
            ans = "1" + ans
        else:
            N //= (-2)
            N += 1
            ans = "1" + ans
ans = "1" + ans    
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  if n==0:
    return 0

  ans=''
  while n!=0:
    if n%2==0:
      ans='0'+ans
    else:
      ans='1'+ans
    n//=2
    n=-n

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
n= int(input())

i = 0
base = 1
digits = ''

while n!= 0:
  if n % (base*2) == 0:
    digits += '0'
  else:
    digits += '1'
    n -= base 
  
  i += 1
  base *= -2

if digits=='':
  digits='0'
  
print(digits[::-1])

Submission status: Accepted

Solution code:
N = int(input())
tmp = []
if(N == 0):
  print('0')
else:
  while(abs(N)!=0):
    tmp.append(N%2)
    N = (N - N % 2) // -2
tmp.reverse()
print(''.join([str(n) for n in tmp]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    if N == 0:
        print(0)
        exit()

    ans = [0] * 100

    ruiseki = [1, -2]
    for i in range(2, 100):
        if i & 1:
            ruiseki.append(-2 ** i + ruiseki[i - 2])
        else:
            ruiseki.append(2 ** i + ruiseki[i - 2])

    while N != 0:
        for i in range(100):
            if N < 0 and i & 1 and ruiseki[i] <= N:
                N -= -2 ** i
                ans[i] = 1
                break
            elif N > 0 and not i & 1 and ruiseki[i] >= N:
                N -= 2 ** i
                ans[i] = 1
                break


    ans2 = []
    for i in range(99, -1, -1):
         if ans[i] == 1 or len(ans2) > 0:
             ans2.append(ans[i])

    print("".join(map(str, ans2)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = ''
if N == 0:
    print(0)
    exit()
while N != 0:
    r = N%2
    N = (N-r)//(-2)
    ans += '1' if r else '0'
print(ans[::-1])

Submission status: Accepted

Solution code:
n=-int(input())

ans=""
for i in range(1000):
    ans+=str(n%2)
    n//=-2
    if n==0:
        break
print(ans[::-1])

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
  print(0)
  exit()
s=""
while n!=0:
  if n % 2 == 1:
    s = "1" + s
    n = (n-1)//2*(-1)
  else:
    s="0"+s
    n=n//2*(-1)
print(s)

Submission status: Accepted

Solution code:

N = int(input())

ans = ''

while N != 0:
    
    
    if N % 2 !=0:
        N -=1
        ans = '1'+ans
    else:
        ans = '0'+ans
    
    N = N//-2

    
if ans == '':
    ans ='0'
    
    
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

if N == 0:
  print(0)
  exit()

ans = ""

while N != 0:
  bit = N % -2
  if (bit < 0):
    bit += 2
  ans = str(bit) + ans
  N = (N - bit) // (-2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = ""
while N != 0:
    if N % 2 != 0:
        N -= 1
        S = "1" + S
    else:
        S = "0" + S
    N //= (-2)
print(S if S != "" else "0")

Submission status: Accepted

Solution code:
N = int(input())
S = ""
while N:
    S += "1" if N%(-2) else "0"
    N -= 1
    N //= -2
print(S[::-1] if S else "0")

Submission status: Accepted

Solution code:
n = int(input())
ans=""
while n!=0:
  if n%2==0:
    ans = "0"+ans
  else:
    n-=1
    ans = "1"+ans
  n//=-2  

if ans=="":
  print("0")
else:
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())

mbits = []

while abs(n) > 0:
    mbits.append(n % 2)
    n = n // 2 * (-1)

if len(mbits) == 0:
    mbits = [0]

ans = map(str, reversed(mbits))
ans = ''.join(ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = []
if N == 0:
  ans.append("0")
while N != 0:
  ans.append(str(N % 2))
  N = -(N // 2)
ans.reverse()
print("".join(ans))

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++


def mkm2(a_ll):
	ccc=0
	for i, c in enumerate(a_ll):
		ccc += ((-2)**i)*(c==1)
	return ccc

def show(a_ll):
	ret = ''.join([str(i) for i in a_ll[::-1]])
	return ret


def main():
	a = int(input())
	if a == 0:
		return 0
	a=-a
	
	ret=[]
	while mkm2(ret) < a and False:
		ret.append(0)
		ret.append(1)
		pa(mkm2(ret))
		pa(ret)
	
	while a != 0:
		if a %(-2)==0:
			ret.append(0)
		else:
			ret.append(1)
		a = a // (-2)
		
	pa(mkm2(ret))
	print(show(ret))
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())

def base_convert(n, b):
    res = ''
    while n:
        r = abs(n % b)
        res = str(r) + res
        n = (n - r) // b

    return int(res) if res else 0

def main():
    return base_convert(n, -2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())

def base_convert(n, base):
    res = []
    b = abs(base)
    while n:
        q, r = divmod(n, b)
        res.append(r)
        n = b * q // base
    try:
        return int(''.join(list(map(str, res)))[::-1])
    except:
        return 0

def main():
    return base_convert(n, -2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())

def to_neg_base(n, neg_base):
    if neg_base > -2:
        sys.exit('base must be at most -2')
    b = abs(neg_base)
    res = [0] * 100
    if n >= 0:
        res[0] = n
        i = 0
    else:
        q, r = divmod(n, b)
        res[0] = r; res[1] = abs(q)
        i = 1

    while res[i] >= b:
        q, r = divmod(res[i], b)
        m = min(q, res[i+1])
        q -= m
        res[i+1] -= m
        res[i] = r
        res[i+1] += (b - 1) * q
        res[i+2] += q
        i += 1

    res = ''.join(list(map(str, res)))[::-1]
    try: 
        return int(res[res.index('1'):])
    except:
        return 0

def main():
    return to_neg_base(n, -2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
    print(0)
else:
    a=abs(n)
    if n>0:
        p=0
    else:
        p=1
    inf=2**p
    while True:
        if a<=inf:
            break
        else:
            p+=2
            inf+=2**p
    sp=p
    while p>=0:
        if p==sp:
            if p%2==0:
                #sn=n
                n-=2**p
                #print(p,str(sn)+"-"+str(2**p)+"="+str(n))
            else:
                #sn=n
                n+=2**p
                #print(p,str(sn)+"+"+str(2**p)+"="+str(n))
            p-=1
            ans="1"
        elif p%2==0 and 2*abs(n)>=abs(n-2**p):
            #sn=n
            n=n-2**p
            #print(p,str(sn)+"-"+str(2**p)+"="+str(n))
            p-=1
            ans=ans+"1"
        elif p%2==1 and 2*abs(n)>=abs(n+2**p):
            #sn=n
            n=n+2**p
            #print(p,str(sn)+"+"+str(2**p)+"="+str(n))
            p-=1
            ans=ans+"1"
        else:
            #print(p,"else")
            p-=1
            ans=ans+"0"
    if len(ans)<sp+1:
        ans+="0"*(sp+1-len(ans))
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = []
if N == 0:
  a = ["0"]
while N != 0:
  a.append(str(N % 2))
  N = -(N // 2)
  # N = -(N - N % 2) // 2
print("".join(list(reversed(a))))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = ""
    base = 2
    while N:
        S = str(N % base) + S
        N -= N % base
        N //= -base
    print(S if S else "0")
    return


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = ""
    base = 2
    while N:
        S = str(N % base) + S
        if N % base:
            N -= N % base
        N //= -base
    print(S if S else "0")
    return


main()