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())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if ans != "":
    print(ans)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import collections
import itertools
import sys

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s=input()
k=len(s)
n=int(s)

m = 2
p = 1
res = []
while True:
    modulo = (n % m + m) % m
    n -= p if modulo else 0
    res.append(1 if modulo else 0)
    m *= 2
    p *= -2
    if not n:
        break

for d in reversed(res):
    print(d, end="")
print("")

Submission status: Accepted

Solution code:
n = int(input())

i = 1
s = ""
count = 0
while count != n:
    if i%2 == 1:
        if (n-count)%(2**i)==0:
            s = "0" + s
        else:
            s = "1" + s
            count += 2**(i-1)
    else:
        if (n-count)%(2**i)==0:
            s = "0" + s
        else:
            s = "1" + s
            count -= 2**(i-1)
    i+=1
if n==0:
    s = "0"
print(s)

Submission status: Accepted

Solution code:
n = int(input())

l = []

if n == 0:
    l.append('0')

while n:
    if n % 2:
        l.append('1')
    else:
        l.append('0')
    n = -(n // 2)

print(''.join(reversed(l)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
flaga=True
S='1'
N=int(input())
D=N
flag=0
p=1
K=0
if N==0:
    print(0)
    exit(0)
elif N==1:
    print(1)
    exit(0)
elif N>0:
    D-=1
    while flag==0:
        if D+1-p>0:
            D-=p
            p*=4
            K+=2
        else:
            #print(D)
            for i in range(K):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'
                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                p=p//2
                flaga = not flaga
                #print(D,flaga,p)
            print(S)
            exit(0)
else:
    D=abs(D)-1
    p+=1
    while flag==0:
        if D-p>=0:
            D-=p
            p*=4
            K+=2
            #print(D,p)
        else:
            #print(D,K)
            for i in range(K+1):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'

                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                flaga = not flaga
                p=p//2

            print(S)
            exit(0)

Submission status: Accepted

Solution code:
N = int(input())

ans = ''
isOdd = False
while N != 0 :
    if N % 2 == 1 :
        ans += '1'
    else :
        ans += '0'
    if isOdd :
        N += 1
    N //= 2
    isOdd = not isOdd

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

Submission status: Accepted

Solution code:
N = int(input())

res = N
S = ''
divisor = 1
i = 0
while res != 0:
    divisor *= 2
    remainder = abs(res) % divisor
    bit = 0 if remainder == 0 else 1
    S = str(bit) + S
    if i % 2 == 0:
        res -= divisor * bit // 2
    else:
        res += divisor * bit // 2
    i += 1
print(S or '0')

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
if N == 0:
    print(0)
    exit()

ans = ''
odd = False
while abs(N) > 0:
    if N & 1:
        ans += '1'
    else:
        ans += '0'
    if odd:
        N += 1
    N >>= 1
    odd = not odd
print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())

i = 1
ans = ""
while N != 0:
    if N % abs(i*2) != 0:
        ans += "1"
        N -= i
    else:
        ans += "0"
    i *= -2
    
if ans == "":
    ans = "0"
print(ans[::-1])

Submission status: Accepted

Solution code:
n = int(input())


if n ==0:
    print(0)

elif n == 1:
    print(1)

else:
    l = []
    while n!=0 and n!=1:
        if n > 0:
            sho = -(n//2)
        else:
            sho = -(-n//(-2))
        amari = n-sho*(-2)
        l = [amari] + l
        n = sho

        if n == 1:
            l = [1] + l

    print("".join(list(map(str, l))))

Submission status: Accepted

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

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:
n = int(input())
cnt = 0
ans = 0
while n != 0:
  now = n % 2
  n = - (n // 2)
  ans += now * 10 ** cnt
  cnt += 1
print(ans)

Submission status: Accepted

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

S = ""

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

Submission status: Accepted

Solution code:
n=int(input())

ans=''

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

Submission status: Accepted

Solution code:
N = int(input())


def f(b, n):
    #print(b, n)
    if n == 0:
        return ""
    
    return f(b, (n + n % b) // b) + str(-(n % b))
if N != 0:
    print(f(-2, N))
else:
    print(0)

Submission status: Accepted

Solution code:
"""
N進数
下記を繰り返して構築
NからNで割ったあまりを引く
そっからNで割る
"""
N = int(input())
if N == 0:
    print(0)
    exit(0)
ans = ""
mod = -2 
while N!=0:
    d = N % abs(mod)
    ans = str(d) + ans
    N -= d
    N //= mod
    # print(N)
print(ans)

Submission status: Accepted

Solution code:
x=int(input())
if x==0:
    print(0)
else:
    s=[]
    while x:
        if x>0:
            t=0
            d=0
            while t<x:
                t += 4**d
                d += 1
            s.append(d*2-1)
            x -= 4**(d-1)
        elif x<0:
            t=0
            d=0
            while t>x:
                t -= 2*(4**d)
                d += 1
            s.append(d*2)
            x += 2*4**(d-1)
    s2 = [0]*max(s)
    for i in s:
        s2[i-1] = 1
    print("".join([str(i) for i in s2[::-1]]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def digi(res):
    t = 1
    if res == 1:return (1,0)
    elif res>0:
        while True:
            if res<=((4**t)-1)//3:break
            t+=1
        r=res-4**(t-1)
        return (2*t-1,r)
    else:
        while True:
            if res>=-2*((4**t)-1)//3:break
            t+=1
        r=res-(-2*(4**(t-1)))
        return (2*t,r)
    
N = int(input())

if N == 0:print(0)
else:
    d = digi(N)
    ld = d[0]
    s=['0'] * d[0]
    s[0] = '1'

    while True:
        if d[1] != 0:
            d = digi(d[1])
            s[ld-d[0]]='1'
        else:break
    print(''.join(s))

Submission status: Accepted

Solution code:
import sys
n = int(input())
s=[]
i=0
if n==0:
  print(0)
  sys.exit()
while n != 0:
  if n%(2**(i+1))!=0:
    a=1
  else:
    a=0
  s.append(a)
  n=n-a*(-2)**i
  i+=1

s.reverse()
m=""
for ss in s:
  m+=str(ss)
print(m)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    if N == 0:
        print('0')
        return
    ans = []
    while N != 0:
        m = N % 2
        if m < 0:
            m = m + 2
        N = (N-m) // -2
        ans.append(m)
    print(''.join(str(_) for _ in ans[::-1]))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
a = []
num = 0
while n != 0:
    if n % (2 ** (num + 1)) == 0:
        a.append(0)
    else:
        a.append(1)
        n -= (-2) ** num
    num += 1
a.reverse()
if a:
    a = map(str, a)
    print("".join(a))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())

def kansu(n):
    ans = ""
    i = True
    while not(n == 0):
        #print(n)
        if n%2 == 0:
            n = n // 2
            ans = "0" + ans
        else:
            ans = "1" + ans
            if i:
                n += -1
            else:
                n += 1
            n = n // 2
        i = i ^ True
        
    if ans == "":
    	ans += "0"
    return ans
  

print(kansu(n))

Submission status: Accepted

Solution code:
N = int(input())

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

ans = ''
while N != 0:
    r = abs(N % 2)
    N = (N - r) // -2
    ans += str(r)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    if n % k:
        print(1)
    else:
        print(0)
    return

#B
def B():
    n = II()
    dp = [0] * (100 + 1)
    dp[4] = 1
    dp[7] = 1
    for i in range(8,n + 1):
        if dp[i - 4] or dp[i - 7]:
            dp[i] = 1
    print(["No", "Yes"][dp[n]])
    return

#C
def C():
    n = II()
    ans = []
    if n == 0:
        print(0)
    while n:
        ans.append("{}".format(n % 2))
        n = (n-1) // -2
    print("".join(ans[::-1]))
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
n = int(input())

ans = ""
if n == 0:
	print("0")
else:
	while n != 0:
		r = n%2
		ans = str(r) + ans
		n -= r
		n = n // (-2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def dev(n):
    if n == 0:
        return ""
    if n%2 == 0:
        return dev(n//(-2))+"0"
    else:
        return dev((n-1)//(-2))+"1"

res = dev(N)
if N == 0:
    res = "0"
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC105C
import sys

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

res=[]

if(n==0):
	print("0")
	sys.exit()

while(1):
	#print(n)
	if(n==0):
		break
	if n%2==1:
		res.append(1)
		n-=1
		n=n//(-2)
	else:
		res.append(0)
		n=n//(-2)

res2=""
for i in range(0,len(res)):
	#res2=res2+str(res[len(res)-i-1])
	res2=res2+str(res[-i-1])
print(res2)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
if n==0:
    print(0)
    exit()
    
for i in range(100):
    if  n==0:
        break
    if n%(2**(i+1))==0:
        ans.append('0')
    else:
        if i%2==0:
            n-=2**i
        else:
            n+=2**i
        ans.append('1')
ans.reverse()
print(''.join(map(str, ans)))

Submission status: Accepted

Solution code:
n = int(input())
x = 1
v = []
while n != 0:
    m = abs(n % 2)
    v.append(m)
    n = (n - m) // -2

if len(v) == 0:
    v.append(0)

print(''.join(map(str, reversed(v))))

Submission status: Accepted

Solution code:
N = int(input())

def max_positive_num(L):
    val = 0
    for i in range(L):
        if i % 2 == 0:
            val = val + 2 ** i
    return val


def min_negative_num(L):
    val = 0
    for i in range(L):
        if i % 2 == 1:
            val = val - 2 ** i
    return val


# 与えた数字に対して最大のビット数を返す
def maxbit(num):
    count = 0
    while not (min_negative_num(count) <= num <= max_positive_num(count)):
        count = count + 1
    return count

bitlist = [0]*maxbit(N)

if N == 0:
    print("0")
else:
    rest = N
    for i in range(maxbit(N), 0, -1):
        if i % 2 == 0:
            if (min_negative_num(i) <= rest < min_negative_num(i-1)):
                bitlist[i-1] = 1
                rest = rest - pow(-2,(i-1))
        else:
            if (max_positive_num(i-1) < rest <= max_positive_num(i)):
                bitlist[i-1] = 1
                rest = rest - pow(-2,(i-1))
    ans = ''.join(map(str, bitlist))
    print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())

def order2(x):
  if x > 0 :
    k = 0
    check = 0
    while check == 0 :
      s = 0
      for i in range(0, k+1, 2):
        s += (-2)**i
        ans = i
      if s >= x:
        check = 1
      k += 2
  elif x < 0 :
    k = 1
    check = 0
    while check == 0 :
      s = 0
      for i in range(1, k+1, 2):
        s += (-2)**i
        ans = i
      if s <= x:
        check = 1
      k += 2
  return ans

if N!= 0 :


  l = [] 
  a = N
  i = order2(N)
  while i >= 0:
    if a == 0 :
      l.append('0')
    if a > 0 and (-2)**i >0 :
        s = 0
        for j in range(0, i, 2):
          s += (-2)**j
        if a > s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    elif a > 0 and (-2)**i < 0:
        l.append('0')
    elif a < 0 and (-2)**i > 0:
        l.append('0')
    elif a < 0 and (-2)**i < 0:
        s = 0
        for j in range(1, i, 2):
          s += (-2)**j
        if a < s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    i -= 1

  print(''.join(l))

else :
  print(0)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    if n == 0:
        print('0')
    elif n > 0:
        c = 1
        cnt = 0
        while True:
            if c + (4**cnt) > n:
                break
            else:
                c += (4**cnt)
                cnt+=1

        ans = '1'
        for i in range(cnt):
            ans+='10'
        
        print(bin(int(ans,2)^int(bin(n-c)[2:],2))[2:])

    else:
        n = abs(n)
        c = 1
        cnt = 0
        while True:
            if c+2*(4**cnt) > n:
                break
            else:
                c+= 2*(4**cnt)
                cnt+=1
        
        ans = '1'
        for i in range(cnt):
            ans+='10'
        ans += '1'
        print(bin(int(ans,2)^int(bin(n-c)[2:],2))[2:])




main()

Submission status: Accepted

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

print(S[::-1])

Submission status: Accepted

Solution code:
N = int(input())
ans = ""
i = 1
while N != 0:
    if N % (2 ** i) == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
        N -= ((-2) ** (i-1))
    i += 1
if len(ans) > 0:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())

a = N
b = 0
B = []
if a == 0:
    B = [0]
while a:
    if a % 2 == 0:
        a, b = a//(-2) , 0
    else:
        a, b = a//(-2)+1, 1
    B.append(b)

B = B[::-1]
print(''.join([str(b) for b in B]))

Submission status: Accepted

Solution code:
N = int(input())
i = 0
ans = []
if N == 0:
  print(0)
  exit()
while N:
  if N%(2)**(i+1) > 0:
    ans.append(1)
    N -= (-2)**i
  else:
    ans.append(0)
  i += 1
ans.reverse()
print("".join(map(str,ans)))

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
s = ""
while N != 0:
    r = N % 2
    if r < 0:
        r += 2
    N = (N - r) // -2
    s += str(r)
if s == "":
    s = "0"
print(s[::-1])

Submission status: Accepted

Solution code:
N = int(input())
def m_bit(N):
    global temp
    global judge
    if N == 0:
        temp = [0]
        n = 0
        judge = "OK"
        return N
    else:
        n = 0
        while abs((-2)**n) <= abs(N):
            if (-2)**n == N:
                temp = [n] + temp
                judge = "OK"
                return N
            n += 1
    if abs((-2)**n) > abs(N):
        if N%2 == 0:
            temp = ["2times"] + temp
            return N*(-1)/2
        else:
            temp = ["minus1"] + temp
            return N-1

temp = []
ans = []
judge = "Yet"

while judge == "Yet":
    N = m_bit(N)

if N == 0:
    print("0")
else:
    ans.append(temp[0])
    for i in range(len(temp)):
        if temp[i] == "minus1":
            ans.append(0)
        elif temp[i] == "2times":
            for j in range(len(ans)):
                ans[j] += 1
    c = 0
    for k in range(len(ans)):
        c += 2**ans[k]
    anser = format(c, "b")
    print(anser)

Submission status: Accepted

Solution code:
n=int(input())

x=[]
tot=0

for i in range(100):
	if n==0:
		x.append(0)
		break
	if (n-tot)%((-2)**(i+1))!=0:
		x.append(1)
		tot+=(-2)**i
		if tot==n:
			break
	else:
		x.append(0)

res=''

for i in x[::-1]:
	res=res+str(i)
        
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s,i=0,0
while n!=0:
    i+=1
    if n&(2**i-1)!=0:
        s+=2**(i-1)
        n-=(-2)**(i-1)
print(bin(s)[2:])

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())

n = N
ans = ''
even = False
for i in range(100):
    if n % 2 == 1:
        ans += '1'
    else:
        ans += '0'
    n += even
    n //= 2
    even = not even
ans = ans[::-1].lstrip('0')
if ans:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())

if N >= 0:
    e = 2
    n = N
else:
    e = 1
    n = -N
while e <= n:
    if n & e:
        n += e << 1
    e <<= 2
print(bin(n)[2:])

Submission status: Accepted

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

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

while n != 0:
    i = n % (-2)
    n = n // (-2)
    if i < 0:
        i += 2
        n += 1
    ans += str(i)

print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())
ite = 0
ans = 0
while(abs(N) > 0):
    if abs(N) % 2 != 0:
        ans += 10 ** ite
        if ite % 2 == 0:
            N -= 1
        else:
            N += 1
    N = N//2
    ite += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

ret = ''
base = 1
while N != 0:
    if N % (base * 2):
        ret = '1' + ret
        N -= base
    else:
        ret = '0' + ret
    base *= -2

print(ret)

Submission status: Accepted

Solution code:
N = int(input())

t = N
ans = ''
while t != 0:
    r = t % 2
    ans = str(r) + ans
    t -= r
    t //= -2
print(ans if ans else '0')

Submission status: Accepted

Solution code:
N = int(input())

t = N
ans = ''
while t != 0:
    q, r = divmod(t, 2)
    ans = str(r) + ans
    t = -q
print(ans if ans else '0')

Submission status: Accepted

Solution code:
n = int(input())
tmp = 1
lipos = [1]
while tmp<10**9:
  tmp *= 4
  lipos.append(lipos[-1]+tmp)
#print(lipos)
tmp = -2
lineg = [-2]
while tmp > - 10**9:
  tmp *= 4
  lineg.append(lineg[-1]+tmp)
#print(lineg)
if n == 0:
  print("0")
elif n == 1:
  print("1")
elif n == -1:
  print("10")
elif n > 0:
  flag = True
  i = 0
  while flag:
    if lipos[i] < n <= lipos[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = lipos[k]-n
  print(bin(lipos[k]^diff)[2:])
else:
  flag = True
  i = 0
  while flag:
    if lineg[i] > n > lineg[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = n-lineg[k]
  print(bin((-lineg[k])^diff)[2:])

Submission status: Accepted

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

print(0 if ans == "" else "".join(reversed(list(ans))))

Submission status: Accepted

Solution code:
n = int(input())

4 // (-2)

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

    n = n // (-2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

    if n >= 0:
        n = n // 2 * (-1)
    else:
        n = abs(n) // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = []
def divide(a):
    if a == 1:
        s.append("1")
        return
    amari = a % 2
    shou =  (a - amari) // (-2)
    s.append(str(amari))
    divide(shou)
if n:
    divide(n)
    print("".join(reversed(s)))
else:
    print(n)

Submission status: Accepted

Solution code:
n = int(raw_input())
def positive(n):
    m = 1
    d = 0
    while m < n:
        d += 2
        m += 2**d
    d -= 1
    s = "1"
    while d >= 0:
        if d % 2 == 1:
            if m + (-2)**d >= n:
                s += "1"
                m += (-2)**d
            else:
                s += "0"
        else:
            if m - 2**d >= n:
                m -= 2**d
                s += "0"
            else:
                s += "1"
        d -= 1
    return s
            
def negative(n):
    if n == -1:
        return "11"
    m = -2
    d = 1
    while m > n:
        d += 2
        m += (-2)**d
    s = "1"
    d -= 1
    while d >= 0:
        if d % 2 == 0:
            if m + 2**d <= n:
                s += "1"
                m += 2**d
            else:
                s += "0"
        else:
            if m - (-2)**d <= n:
                s += "0"
                m -= (-2)**d
            else:
                s += "1"
        d -= 1
    return s
    
                
        

def makeS(n):
    if n == 0:
        return "0"
    elif n > 0:
        return positive(n)
    else:
        return negative(n)
print makeS(n)

Submission status: Accepted

Solution code:
import math
n = int(input())
ans = 0
i = 0
while n is not 0:
  if n % (-2)**(i+1):
    ans += 10**i
    n -= ((-2)**i)
  i += 1  
print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())

ans=''
if N==0:
    ans='0'
while N!=0:
    r=N-(-2)*int(N/(-2))
    N=int(N/(-2))
    if r<0:
        r=-r
        N+=1
    ans=str(r)+ans
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
bin_n = bin(n)
ranges = []

def base_minus2(m, i, s):
    tmp = s
    if i == 1:
        return tmp + str(m%2)
    for j in range(i-1, -1, -1):

        if m >= ranges[j-1][0] and m <= ranges[j-1][1]:
            tmp += "1"
            return base_minus2(m-(-2)**j, j, tmp)
        else:
            if j == 0:
                return tmp + str(m%2)
            else:
                tmp += "0"


if n == 0:
    print("0")
elif n == 1:
    print("1")
else:
    for i in range(1, 60):
        min_r = sum([(-2)**j for j in range(1, i, 2)]) + (-2)**i
        max_r = sum([(-2)**j for j in range(0, i, 2)]) + (-2)**i
        ranges.append([min_r, max_r])

    result = base_minus2(n, 60, "")
    print(result.lstrip("0"))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

def plus_idx(num):
  return 2 * int(np.ceil(np.log2(1 + 3*num)/2)) - 2

def minus_idx(num):
  return 2 * int(np.ceil(np.log2(1 + 3 * abs(num) / 2)/2)) - 1

def return_idx(num):
  if num == 0:
    return 0
  elif num > 0:
    return plus_idx(num)
  else:
    return minus_idx(num)
    
def minus_two_recur(num, l):
  if num == 0:
    return 0, l
  elif num > 0:
    idx = plus_idx(num)
    l[-(idx+1)] = 1
    new_num = num - (-2)**idx
    return new_num, l
  elif num < 0:
    idx = minus_idx(num)
    l[-(idx+1)] = 1
    new_num = num - (-2)**idx
    return new_num, l

num = n
max_length = return_idx(num)
result = [0] * (max_length+1)
while num != 0:
  num, result = minus_two_recur(num, result)

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

Submission status: Accepted

Solution code:
# 写経
N = int(input())


ans = ""
if N == 0:
    ans = "0"


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


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

swap_bin = {'0':'1', '1':'0'}

M = N
for i in range(20):
  M += 2**(2*i+1)
  
binary = str(bin(M)[2:])
#print(binary)

solver = []
for i in range(1,len(binary)+1):
  if i % 2 == 0:
    solver.append(swap_bin[binary[-i]])
  else:
    solver.append(binary[-i])
    
solver = solver[::-1]
ans = ''.join(solver)
print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
i = 0
S = ""

while N != 0 or i == 0:
  if N % ((-2)**(i+1)) == 0:
    S = "0" + S
  else:
    S = "1" + S
    N = N - (-2)**i
  i += 1
print(S)

Submission status: Accepted

Solution code:
from math import ceil

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

ans=''

while n!=0:
    ans+=str(abs(n)%2)
    n=ceil(n/-2)
print(ans[::-1])

Submission status: Accepted

Solution code:
from math import log
n = int(input())
s = ""
if n != 0:
    for i in range(int(log(abs(n),2))+3):
        #print("i=",i)
        if n % 2**(i+1) == 2**i:
            s = "1" + s
            n -= (-2)**(i)
            #print(i,n)
        else:
            s = "0" + s
    for j in s[s.find("1"):]:
        print(j,end = "")
else:
    print(0)

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=n//(-2)
if s=="":
    s="0"
print(s)

Submission status: Accepted

Solution code:
N = int(input())
s = ''
i = 0
while N != 0:
    tmp = N % 2
    s += str(tmp)
    N = N - tmp * (-1) ** i
    N = (N // 2)
    i += 1
s = s[::-1]
if s == '':
    print(0)
else:
    print(s)

Submission status: Accepted

Solution code:
N = int(input())
s = ''
i = 0
while N != 0:
    tmp = N % 2
    s += str(tmp)
    N = N - tmp * (-1)**i
    N = (N//2)
    i += 1
s = s[::-1]
if s == '':
    print(0)
else:
    print(s)