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:
N = int(input())

if N==0:
    print(0)
else:
    answer=[]
    while N != 0:

        if N % (-2) == 0:
            N=N//(-2)
            answer.append(0)
        else:
            N=N//(-2)+1
            answer.append(1)

    print(''.join(list(map(str, reversed(answer)))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

A = []
if n == 0:
    print(0)
else:
    while(n != 1):
        if n % (-2) == -1:
            t = n // (-2) + 1
            n =  t
            A.append('1')
        else:
            A.append('0')
            t = n // (-2)
            n = t
    A.append(str(n))
    A = A[::-1]
    print("".join(A))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()

if n == 0:
    print(0)
else:
    ans = ""
    while n != 0:
        if n & 1:
            n -= 1
            ans = '1' + ans
        else:
            ans = '0' + ans
        n //= -2
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = []
#now = (-2)^n = 1,-2,4,-8,16....
now = 1
while n != 0:
    if n % (abs(now) * 2) == 0:
        ans.append("0")
    else:
        ans.append("1")
        n -= now

    now *= -2
    #print(n, now, ans)

if ans == []:
    print(0)
else:
    out = ""
    for i in range(len(ans) - 1, -1, -1):
        out += ans[i]

    print(out)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    ans = ""
    while abs(n) > 1:
        if n % 2 == 0:
            ans += "0"
            n //= 2
            n *= -1
        else:
            ans += "1"
            n //= 2
            n *= -1

    if n == -1:
        ans += "11"
    else:
        ans += str(n)

    ans = ans[::-1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

S = ""
for i in range(100):
    if abs(N) % (2 ** (i+1)) != 0:
        S += "1"
        N -= (-2) ** (i)
    else:
        S += "0"
    if N == 0:
        break

print(S[::-1])

Submission status: Accepted

Solution code:
N=int(input())
ans=''
for i in range(33):
    if N%pow(2,i+1):
        ans+='1'
        N-=pow(-2,i)
    else:
        ans+='0'
print(int(ans[::-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

# input
N = int(input())


def solve(x):
    ans = []
    while x != 1:
        if x % 2 == 1:
            ans.append(1)
            x = (x - 1) // -2
        else:
            ans.append(0)
            x //= -2
    
    ans.append(1)
    s = sum([-2 ** i for i in range(len(ans)) if ans[i] == 1])
    if s != x:
        ans = ans[::-1]
    print("".join(map(str, ans)))


def main():
    if N == 0:
        print(0)
    else:
        solve(N)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
b = -2
a = []
def d(n):
    if n > 0:
        return -(-n//b)
    elif n < 0:
        return (n-1)//b
def r(n):
    if n%b < 0:
        return -(n%b)
    else:
        return n%b

while N != 0 and N != 1:
    a.append(r(N))
    N = d(N)
if N == 1:
    a.append(N)
else:
    a.append(0)

a.reverse()
ans = "".join(map(str,a))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = ""
while n != 0:
    rest = n % 2
    if rest == 1:
        ans += "1"
    else:
        ans += "0"

    n = (n - rest) // -2

if ans == "":
    ans += "0"

print(ans[::-1])

Submission status: Accepted

Solution code:
n = int(input())

ans = ""
while n != 0:
    rest = n % 2
    if rest == 1:
        ans += "1"
    else:
        ans += "0"

    n = (n - rest) // -2

if ans == "":
    ans += "0"

print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)
else:
    ret = ""
    while N != 0:
        if N % 2 != 0:
            N -= 1
            ret = "1" + ret
        else:
            ret = "0" + ret
        N //= -2
    print(ret)

Submission status: Accepted

Solution code:

n = int(input())
if n == 0:
    print(0)
    exit()
bit = []
while n != 0:
    bit.append(-(-n % -2))
    n = -(-n // -2)

for i in range(len(bit) - 1, -1, -1):
    print(bit[i], end = "")
print()

Submission status: Accepted

Solution code:
n=int(input())
A=[1]
for i in range(15):
  A.append(A[-1]+4**(i+1))
B=[-2,-1]
for i in range(15):
  B.append(A[i]+1)
  B.append(A[i+1])
  B.append(-2*A[i+1])
  B.append(-2*A[i]-1)
C=[1]
for i in range(32):
  C.append(C[-1]*-2)
if n==0:
  print(0)
  exit()
if n==1:
  print(1)
  exit()
a=0
i=0
while a==0:
  if B[2*i]<=n and n<=B[2*i+1]:
    a=1
  else:
    i=i+1
ans=""
while i>=0:
  if B[2*i]<=n and n<=B[2*i+1]:
    ans=ans+"1"
    n=n-C[i+1]
    i=i-1
  else:
    ans=ans+"0"
    i=i-1
if n==0:
  ans=ans+"0"
else:
  ans=ans+"1"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
q = []
i = 1
if n == 0:
    q.append(0)
while True:
    if n == 0:
        break
    if abs(n - i) % abs(-2 * i) == 0:
        q.append(1)
        n -= i
    else:
        q.append(0)
    i *= -2
q.reverse()
print("".join(map(str, q)))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    # n進数
    n = int(input())
    k = -2
    if n==0:
        print(0)
    else:
        bi = ''
        while n != 0:
            bi += str(n % abs(k))
            if k < 0:
                n = -(-n // k)
            else:
                n = n // k
        print(bi[::-1])


resolve()

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = collections.deque()
while True:
	a.appendleft(N % 2)
	if N % -2 == -1:
		N -= 2
	N //= -2
	if not N:
		break
for i in a:
	print(i, end='')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import *
from heapq import *
N=int(input())
if N==0:
    print(0)
    exit()
num=0
count=0
lst=[]

while N:
    if N%2==1:
        lst.append(1)
        N-=1 * (-1 if count%2 else 1)
    else:
        lst.append(0)
    count+=1
    N//=2
lst=list(reversed(lst))
print("".join([str(i) for i in lst]))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

    ans = []
    while N != 0:
        r = N % 2
        if r < 0:
            r += 2
        ans.append(r)
        N -= r
        N //= -2
    print("".join(map(str, ans[::-1])))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    result = ""
    while N:
        result = str(N % 2) + result
        N = (N - N % 2) // -2
    print(result or 0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7


    N = II()
    if N == 0:
        print(0)
        return
    ans_stack = deque()
    determined = 0
    for i in range(100):
        if (N - determined) % 2 ** (i+1) != 0:
            ans_stack.append(1)
            determined += (-2) ** i
        else:
            ans_stack.append(0)
        if determined == N:
            break
    ans_str = ''
    while len(ans_stack) > 0:
        item = ans_stack.pop()
        ans_str += str(item)
    print(ans_str)
    '''
    1 -2 4 -8 16 -32 64 -128
    '''
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
N = 2**32 + N
#print(N)
buf = [0]*35
for i,s in enumerate(bin(N)[2:][::-1]):
    if s == "1":
        buf[i] = 1
#print(buf)

ans = [0]*35

for i in range(33):
    if buf[i]==1:
        if i%2==0:
            ans[i]+=1
        else:
            ans[i]+=1
            ans[i+1]+=1
    while ans[i]>=2:
        ans[i]-=2
        ans[i+1]+=1
        ans[i+2]+=1
    #print(ans)
first = True
ans[33]-=1

a = ""
for i in ans[:32][::-1]:
    if first:
        if i==1:
            first=False
    if not first:
        a += str(i)
if a!="":
    print(a)
else:
    print(0)
"""
s = a
a = 0
b = 1
for i in s[::-1]:
    if i=="1":
        a+=b
    b *= -2
print(a)
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#print(1//-2)

n = int(input())
if n==0:
  print(0)
else:
  result = ''
  while n!=0:
    #print(n)
    if n%-2==0:
      result+='0'
      n = n//-2
      #n+=1
    else:
      result+='1'
      if n<0:
        n = n//-2
        n+=1
      else:
        n = n//-2
        n+=1
  result = result[::-1]
  print(result)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
i = 1
while n:
  r = n % 2
  if r < 0:
    r += 2
  n = (n - r) // (-2)
  ans += r * i
  i *= 10

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m = n
a = []

for _ in range(400):
    if n > 0:
        if n % 2 == 1:
            n = - (n // 2)
            a.append(1)
        else:
            n = -(n // 2)
            a.append(0)
    elif n < 0:
        if (-n) % 2 == 1:
            n = n // (-2) + 1
            a.append(1)
        else:
            n = n // (-2)
            a.append(0)
    
a.reverse()
ans = ''.join([str(i) for i in a])

if m != 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
from math import ceil

n = int(input())

res = []
while n != 0:
    res.append(n % 2)
    n = ceil(n / -2)
if res == []:
    res.append(0)

print(''.join([str(i) for i in res[::-1]]))

Submission status: Accepted

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

ans=""
while n:
    if n%2:
        ans+=str(1)
        n-=1
    else:
        ans+="0"
    n//=-2
print(ans[::-1])

Submission status: Accepted

Solution code:

n=int(input())
if(n==0):
    print(0)
    exit()
s=""
c=0
while(n!=0):
    if(abs(n)%2==0):s+='0'
    else:
        s+='1'
        if(c%2==0):n-=1
        else:n+=1
    c+=1
    n/=2
    if(c>=100):break
        
t=reversed(s)
for x in t:print(x,end="")

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  if n == 0:
    print('0')
    return

  bi = [0]*2 + list(map(int, bin(abs(n))[2:]))

  posi = True if n > 0 else False
  for i in range(len(bi))[::-1]:
    if bi[i] == 2:
      bi[i] = 0
      bi[i-1] += 1
    elif not posi and bi[i] == 1:
      bi[i-1] += 1
    posi ^= True
  print(''.join(map(str, bi)).lstrip('0'))
  return

main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=''
  if n==0:
    return 0

  while True:
    if abs(n)==0:
      return ans

    if n%2==0:
      ans='0'+ans
    else:
      ans='1'+ans
    n//=2
    n*=(-1)

# main()
print(main())

Submission status: Accepted

Solution code:
import sys
N = int(input())
s = ''
s2 = ''
if N == 0:
  print(0)
  sys.exit(0)
while N != 0:
  if N % 2 == 0:
    s += '0'
    N //= (-2)
  if N % 2 == -1 or N % 2 == 1:
    s += '1'
    N //= (-2)
    N += 1
s2 = s[::-1]
print(s2)

Submission status: Accepted

Solution code:
# 解説AC

N = (-1) * int(input())

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

ans = ""

while N != 0:
    N, r = divmod(N, -2)

    ans += "1" if r else "0"

print(ans[::-1])

Submission status: Accepted

Solution code:
N=int(input())
l=[]
c=0
while True:
  if N==0:
    break
  else:
    c+=1
    if N%(2**c)==0:
      l.append(0)
    else:
      l.append(1)
      N-=(-2)**(c-1)
if l==[]:
  print(0)
else:
  ans=0
  for i in range(len(l)):
    ans+=int(l[i]*(10**(i)))
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())
key = []
if n%2:
  key.append("1")
  n -= 1
else:
  key.append("0")

bef_p, bef_q = 0, 0
n //= 2
while n:
  k_p, k_q = (n//2)%2, n%2
  if k_p == 0:
    if k_q == 0:
      key.append("0")
      key.append("0")
      bef_p, bef_q = 0, 0
    else:       
      key.append("1")
      key.append("1")
      bef_p, bef_q = 0, 0      
  else:
    if k_q == 0:
      key.append("0")
      key.append("1")
      bef_p, bef_q = 0, 0
    else:
      key.append("1")
      key.append("0")
      bef_p, bef_q = 1, 1
  n //= 4
  n = n + bef_p*2-bef_q
key.reverse()
print(int("".join(key)))

Submission status: Accepted

Solution code:
N = int(input())

def nega_binary(num):
    if num == 0:
        return 0
    res = []
    while num != 0:
        remainder = abs(num) % 2
        res.append(str(remainder))
        if num < 0 and remainder:
            num -= 1
        num = int(num / -2)
    return ''.join(reversed(res))

print(nega_binary(N))

Submission status: Accepted

Solution code:
N = int(input())
k = 0
i = 0
ans = []
while k != N:
    j = pow(-2, i)
    p = '1' if (N - k - j) % pow(2, i + 1) == 0 else '0'
    ans.append(p)
    k += int(p) * j
    i += 1

if N == 0:
    print(0)
else:
    print(''.join(reversed(ans)))

Submission status: Accepted

Solution code:
N = int(input())
ans = [0] * 40
if N == 0:
    print(0)
    exit()
else:
    while N != 0:
        i = 1 if N < 0 else 0
        k = pow(-2, i)
        while abs(N) > abs(k):
            i += 2
            k += pow(-2, i)
        ans[i] = 1
        N -= pow(-2, i)

for j in range(39, -1, -1):
    if ans[j] == 1:
        print(''.join(map(str, reversed(ans[:j + 1]))))
        exit()

Submission status: Accepted

Solution code:
n=int(input())
s=0
k=0
ans=[]
if n==0:
  print(0)
while n!=0:
  if k%2==0:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n-=x
  else:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n+=x
  k+=1
print(''.join(ans)[::-1])

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []

while N :
    r = abs(N%2)
    ans.append(int(r))
    N = (N-r)//(-2)

ans.reverse()
print(*ans, sep="")

Submission status: Accepted

Solution code:
n=int(input())
L=[]
cnt=0
while(n!=0):
    cnt+=1
    a=n%(2**cnt)
    b=(1 if a>0 else 0)
    L.append(b)
    n=n-(((-2)**(cnt-1))*b)
L=list(map(str,L))[::-1]
print("".join(L) if len(L)>0 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  s = 0
  ans = []
  for i in range(50):
    if (n - s) % (2**(i+1)) == 0:
      ans.append('0')
    else:
      ans.append('1')
      s += ((-2) ** i)
    if s == n:
      break
  print(''.join(ans[::-1]))
    
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
i = 0
if (n == 0):
    print(0)
    exit()
while (n != 0):
    tmp = 1 if (n % (2 ** (i+1)) != 0) else 0
    n -= (-2) ** i * tmp
    ans = str(tmp)+ans
    i+= 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = ''
while True:
    ans += str(n % 2)
    if(n < 0):
        n = (abs(n) + 1) // 2
    else:
        n = -1 * (n // 2)

    if(n == 1):
        ans += '1'
        break

print(ans[::-1])

Submission status: Accepted

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

if n==0:print(0);exit()
while n!=0:
    ans +=str(n%2)
    n=-(n//2)

print(ans[::-1])

Submission status: Accepted

Solution code:
from sys import exit

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

lst = []
i = 1
while N:
    n2 = N % 2
    lst.append(n2)
    N = (N - n2 * i) // 2
    i *= -1
print(''.join(map(str, reversed(lst))))

Submission status: Accepted

Solution code:

def submit():
    n = int(input())
    s = ""
    c = 0
    base = 1

    def check_mod(n, base, c):
        divider = -2 * base
        tmp = n % divider
        if tmp == c:
            return True
        else:
            # 剰余の符号違いも許容する
            return tmp - divider == c

    while c != n:
        if check_mod(n, base, c):
            s = "0" + s
        else:
            s = "1" + s
            c += base
        base *= -2

    if s:
        print(s)
    else:
        print("0")


if __name__ == "__main__":
    submit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n):
    h = {0:'0', 1:'1', -2:'10', -1:'11'}
    if n in h:
        ret = h[n]
        #ddprint(f"foo {n} ret {ret}")
        return ret
    r = n%4
    if r==0:
        s = '00'
        v = 0
    elif r==1:
        s = '01'
        v = 1
    elif r==2:
        s = '10'
        v = -2
    else:
        s = '11'
        v = -1
    ret = foo((n-v)//4) + s
    #ddprint(f"foo {n} ret {ret}")
    return ret

n = inn()
if n==0:
    print(0)
else:
    s = foo(n)
    for i in range(len(s)):
        if s[i]=='1':
            break
    print(s[i:])

Submission status: Accepted

Solution code:
n = int(input())
Str = ""
while n != 0:
    r = n % 2
    if r < 0:
        r += 2
    n = (n-r) // (-2)
    Str += str(r)
tmp = list(reversed(list(Str)))
ans = "".join(tmp)
if Str == "":
    print(0)
    exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
Str = ""
while (n != 0):
    r = n % 2
    if r < 0:
        r += 2
    # n = (-2)*q + rよりqについて式変形する。q = nとすると
    n = (n-r) // (-2)
    Str += str(r)
tmp = list(reversed(list(Str)))
ans = "".join(tmp)
if Str == "":
    print(0)
    exit()
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math

def main():
    n = int(input())
    n += 1 if n > 0 else -1
    
    s = ""
    while abs(n) > 1:
        c = "1" if n % 2 == 0 else "0"
        s = c+s 
        n = n // -2 + (0 if n > 0 else 1)

    print(0 if not s else s)
main()

Submission status: Accepted

Solution code:
n = int(input())
ans = []
while n!=0 and n!=1:
    ans.append((-n)%2)
    n = -(n//2)
ans.reverse()
ans = [n]+ans
ans = [str(n) for n in ans]
print(''.join(ans))

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n):
    h = {0:'0', 1:'1', -2:'10', -1:'11'}
    if n in h:
        ret = h[n]
        #ddprint(f"foo {n} ret {ret}")
        return ret
    r = n%4
    if r==0:
        s = '00'
        v = 0
    elif r==1:
        s = '01'
        v = 1
    elif r==2:
        s = '10'
        v = -2
    else:
        s = '11'
        v = -1
    ret = foo((n-v)//4) + s
    #ddprint(f"foo {n} ret {ret}")
    return ret

n = inn()
if n==0:
    print(0)
else:
    s = foo(n)
    for i in range(len(s)):
        if s[i]=='1':
            break
    print(s[i:])

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        digit = abs(N%(-2))
        ans += str(digit)
        N -= digit
        N //= -2

    for i in reversed(range(len(ans))):
        print(ans[i],end="")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())

if N == 0:
    ans_list=[0]
else:
    ans_list=[]

while N != 0:
    digit1 = abs( N%(-2) )
    ans_list += [digit1]
    N = (N - digit1) // (-2)
    
print( *ans_list[::-1], sep="" )

Submission status: Accepted

Solution code:
# coding: utf-8

def get_ans():
    n = int(input().rstrip())
    if n == 0:
        return "0"
    dv = 1
    bit_list = []
    while n != 0:
        tmp = n % (dv*2)
        if tmp == 0:
            bit_list.append("0")
        else:
            bit_list.append("1")
        n -= tmp
        dv *= -2
    return "".join(reversed(bit_list))


print(get_ans())

Submission status: Accepted

Solution code:
n = int(input())
 
ansl = []
if n == 0:
    print("0")
    exit()
while n:
    if n % -2 == 0:
        ansl.append("0")
    else:
        n -= 1
        ansl.append("1")
    n = n // -2
 
ansl.reverse()
print("".join(ansl))

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 //= (-2)
if ans == '':
    ans = '0'
print(ans)

Submission status: Accepted

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

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

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

        n /= (-2)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

while n:
    a+=str(n%2)
    n//=-2

print(a[::-1] if a else 0)

Submission status: Accepted

Solution code:
n = int(input())

if n == 0:
    print(0)
    
else:
    a = []
    while n != 0:
        if n%2 == 0:
            a.append(0)
        else:
            a.append(1)
            n -= 1
        n//=(-2)
    
    print(''.join(map(str, a[::-1])))

Submission status: Accepted

Solution code:
N = int(input())

def calculate2(n):
    arr = []
    for i in range(40):

        if n % (2**(i+1)) != 0:
            arr.append(1)
            n = n - ((-2) ** i)
        else:
            arr.append(0)
        if n == 0:
            break

    arr.reverse()
    return arr

result = calculate2(N)
result = "".join([str(s) for s in result])
print(result)

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

x = n

ans = []

if x == 0:
    print(0)
else:
    while  x != 0:
        ans.append(abs(x%(-2)))
        x = (x - ans[-1])/(-2)


    for i in range((len(ans)-1),-1,-1):
        print(int(ans[i]),end="")

    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S =""
for i in range(100):
    if N==0:break
    if N%pow(2,i+1)!=0:
        S+="1"
        N-=pow(-2,i)
    else:S+="0"
print("0" if S=="" else S[::-1])

Submission status: Accepted

Solution code:
a = int(input(""))
list = []
if(a == 0):
    list.append(0)
while(a):
    if(a%(-2)==0):
        list.append(0)
        a//=-2
    elif(a%(-2)==-1):
        list.append(1)
        a -= 1
        a//=-2

list.reverse()
for i in list:print(i,end='')
print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []
t = 1
p = 1

while N!=0:
    if N%(p*2)!=0:
        ans.append(1)
    else:
        ans.append(0)

    N -= ans[-1]*p*t
    t *= -1
    p *= 2

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(ans[::-1])

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())
if N==0:
  print(0)
  exit()

ans = []
while N != 0:
    if N % 2 == 1:
        ans.append("1")
        N -= 1
    else:
        ans.append("0")
    N //= - 2

ans = "".join(ans)[::-1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

kp=-10
km=10
k=0
while not(km<=n and n<=kp):
    k=k+1
    km=-int(2*(4**k-1)/(4-1))
    kp=int((4**k-1)/(4-1))
#    print("n=",n,"k=",k,"km=",km,"kp=",kp)        
#print("n=",n,"n-km=",n-km)

n=n-km

v=""
for kk in range(k):
    np=n//4**(k-kk-1)
    n=n-np*4**(k-kk-1)
    if np==0:
        v=v+"10"
    elif np==1:
        v=v+"11"
    elif np==2:
        v=v+"00"
    elif np==3:
        v=v+"01"
#print("v=",v)

if len(v)>0 and v[0]=="0":
    v=v[1:]
if len(v)>0:
    print(v)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())

res = []
if N != 0:
    while N != 0:
        q, r = divmod(N, -2)

        if r in {0, 1}:
            N = q
        else:
            r = N - (-2) * (q + 1)
            N = q + 1
        res.append(r)
else:
    res.append(0)

print("".join(list(map(str, res[::-1]))))

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print('0')
else:
    ans = ''
    for i in range(100):
        if N == 0:
            break
        if abs(N) % (2**(i+1)) != 0:
            ans += '1'
            N -= (-2)**i
        else:
            ans += '0'

    print(ans[::-1])

Submission status: Accepted

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

if answer == '':
    answer = '0'

print(answer)

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  ans=[]
  if n==0:
    print(0)
  while n!=0:
    s=n%2
    ans.append(s)
    if s==0:
      n//=(-2)
    else:
      n=(n-1)//(-2)
  ans=ans[::-1]
  print(''.join([str(bit) for bit in ans]))
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
n=int(input())
t=[]
x=0
for i in range(60):
    y=((n-x)%(1<<(i+1)))*(-1)**i
    if y==(-2)**i:
        t+=['1']
        x+=(-2)**i
    else:
        t+=['0']
    if x==n:
        break
print(''.join(t)[::-1])

Submission status: Accepted

Solution code:
import math
n=int(input())
ans_rev=""
if n==0:
    print(0)
else:
    while n!=1:
        ans_rev+=str(abs(n%(-2)))
        n=math.ceil(n/(-2))
    ans_rev+="1"
    ans=ans_rev[::-1]
    print(ans)

Submission status: Accepted

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