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:
import sys

N = int(input())

if(N == 0):
    print(0)
    sys.exit()
elif(N < 0):
    mask = 1
    N = -1 * N
else:
    mask = 0
S = bin(N)[2:]

ans = ""

i = 0
up1 = 0
up2 = 0
for c in (reversed(S)):
    if((i + mask) % 2 == 0):
        if(up1 == 1):
            if(c == "0"):
                up1 = 0
                up2 = 0
                ans = "1" + ans
            else:
                up1 = 1
                up2 = 1
                ans = "0" + ans
        else:
            up2 = 0
            up1 = 0
            ans = c + ans
    else:
        if(up2 == 0):
            up1 = int(c)
            up2 = 0
            ans = c + ans
        else:
            up1 = up2
            up2 = 0
            if(c == "0"):
                ans = "1" + ans
            else:
                ans = "0" + ans

    # print(c, i, ans)
    i += 1

# print(up2, up1)
if(up2 == 1):
    ans = str(up2) + str(up1) + ans
elif(up1 == 1):
    ans = str(up1) + ans
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def n_ary_notation(N, n):
  if N == 0:
    return '0'
  else:
    s = ''
    while N:
      s = str(N % abs(n)) + s
      N -= N % abs(n)
      N //= n
    return s
print(n_ary_notation(N, -2))

Submission status: Accepted

Solution code:
N = int(input())
def n_ary_notation(N, n):
  if N == 0:
    return '0'
  else:
    s = ''
    while N:
      s = str(N % abs(n)) + s
      N -= N % abs(n)
      N //= n
    return s
print(n_ary_notation(N, -2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#encoding utf-8

n = int(input())
answer = ""

def kenzan(ans):
    val = 0
    ans.reverse()
    for i in range(len(ans)):
        val += answer[i]*(-2)**i
    return int(val)

i = 1

while(n != 0):
    if n % 2 == 0:
        answer = "0" + answer
    else:
        answer = "1" + answer
        n -= 1
    n /= -2
if answer == "":
    answer = 0
print(answer)
# print(kenzan(answer))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#encoding utf-8

n = int(input())
m=n
answer = []

def kenzan(ans):
    val = 0
    ans.reverse()
    for i in range(len(ans)):
        val += answer[i]*(-2)**i
    return int(val)

i = 1
while(n != 0):
    # print(n)
    if n % (2**i) == 0:
        answer.append(0)
    else:
        answer.append(1)
        n = n-((-2)**(i-1))
    i += 1
answer.reverse()
if answer == []:
    answer.append(0)
print("".join(str(i) for i in answer))
# print(kenzan(answer))

Submission status: Accepted

Solution code:
#coding:utf-8


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())
if n == 0:
    ans = '0'
else:
    ans = ''
    while n != 0:
        if n % 2 == 1:
            ans = '1' + ans
            n -= 1
        else:
            ans = '0' + ans
        n //= -2
print(ans)

Submission status: Accepted

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

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

    ans = []

    if n == 0:
        print(0)
        exit()
    
    while True:
        if n % (-2) == -1:
            ans.append(1)
            n = (n // -2) + 1
        elif n % -2 == 0:
            ans.append(0)
            n //= -2
        if n == 1:
            ans.append(1)
            break
    ans.reverse()
    print(''.join(list(map(str, ans))))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print ans[::-1]

Submission status: Accepted

Solution code:
N=input()

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

print ans[::-1]

Submission status: Accepted

Solution code:
N = float(input())

if N==0:
  print(0)
else:
  q = N
  r_s = []

  while q!=1:
    hoge = (q-1) / (-2)
    if hoge.is_integer():
      r = int(1)
      q = float(hoge)
    else:
      r = int(0)
      q = float(q/(-2))
  
    r_s.append(r)
  r_s.append(1)
  r_s = r_s[::-1]

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

Submission status: Accepted

Solution code:
N = int(input())
n = 0
k = 0
even = True
if N > 0:
    while N > 0:
        if N & 1:
            if even:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
            else:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
        even = not even
        N = N >> 1
        k += 1
else:
    N = -N
    while N > 0:
        if N & 1 != 0:
            if even:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
            else:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
        even = not even
        N = N >> 1
        k += 1
print(bin(n)[2:])

Submission status: Accepted

Solution code:
N=int(input())

lr = ""
i=1

if N==0:
    print(0)

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

        i+=1

    print(lr)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
if N == -1:
  print('11')
  sys.exit()
if N == 0:
  print('0')
  sys.exit()
if N == 1:
  print('1')
  sys.exit()

def num(N):
  mi = 0
  ma = 1
  k = 1
  while mi > N or ma < N:
    mi = min(mi,mi+(-2)**k)
    ma = max(ma,ma+(-2)**k)
    k += 1
  return k-1
rem = 0
ansli = []
def ans(N):
  while abs(N)>0:
    ansli.append(num(N))
    N = N-(-2)**num(N)
  return ansli

ans(N)
answer = ''
m = max(ansli)
while m >= 0:
  if m in ansli:
    answer += '1'
  else:
    answer += '0'
  m += -1
  
print(answer)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N, = map(int, raw_input().split())
i=0
s=""
while N!=0:
  m = 1 if (N%(1<<(i+1))>0) else 0
  s = str(m)+s
  N-= m * ((-2)**i)
  i += 1
print 0 if s=="" else s

Submission status: Accepted

Solution code:
N = int(input())

def solve(N):
    result = ""
    k = 1
    while 1:
        c = N % 2
        result = "01"[c] + result
        N = (N - k * c) // 2
        k = -k
        if N == 0:
            break
    return result

print(solve(N))

Submission status: Accepted

Solution code:
n,ans = int(input()),[]
while n:
	ans.append(str(abs(n)%2))
	n = (n-abs(n)%2)//(-2)
print("".join(reversed(ans)) if ans else "0")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A,S = [0]*32,[0]*32
A[0],A[1],S[0],S[1] = 1,-2,1,-2
for i in range(2,32):
    A[i] = A[i-1]*(-2)
    S[i] = S[i-2] + A[i]

X = ["0"]*32
t = 0
flg = True
while N != 0:
    if N > 0:
        for i in range(32):
            if S[i] >= N:
                break
    else:
        for i in range(32):
            if S[i] <= N:
                break
    X[i] = "1"
    N -= A[i]

print(int("".join(X)[::-1]))

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def n():
    return int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
# print(N)


if N == 0:
    print(0)
elif N > 0:
    co = [0 for i in range(31)]

    a = 2
    i = 1
#    for i in range(29):
    co[0] = N % 2
    while a <= N:
        co[i] = ((N - a) // (2 ** i) + 1) % 2
#        print(i, a, co[i])

        i = i + 1
        if i % 2 == 1:
            if i == 1:
                pass
            else:
                a = a + 2 ** (i - 1)

    ans = 0
    for i in range(31):
        ans = ans + (10 ** i) * co[i]
    print(ans)
else:
    co = [0 for i in range(32)]
    N = - N

    a = 1
    i = 1
    co[0] = N % 2
    while a <= N:
        co[i] = ((N - a) // (2 ** i) + 1) % 2
#        print(i, a, co[i])

        i = i + 1
        if i % 2 == 0:
            a = a + 2 ** (i - 1)

    ans = 0
    for i in range(32):
        ans = ans + (10 ** i) * co[i]
    print(ans)

Submission status: Accepted

Solution code:
N=-int(input())
if N==0:
    print(0)
else:
    tmp=[]
    while N!=0:
        tmp.insert(0,N%(2))
        N=-N//2
    s=''.join([str(_) for _ in tmp])
    print(s)

Submission status: Accepted

Solution code:

N = int(input())

S = ''
if N == 0:
    S = '0'

i=0
while abs(N) > 0:
    if (N % 2 ** (i+1)) == 0:
        S = '0' + S
    else:
        S = '1' + S
        N -= (-2) ** i
    i+=1
print(S)

Submission status: Accepted

Solution code:
N = int(input())

def solve(N):
    if N == 0:
        return "0"
    result = ""
    n = N
    i = 0
    while n:
        k = (-2)**i
        if n & (1 << i):
            n -= k
            result = "1" + result
        else:
            result = "0" + result
        i += 1
    return result

print(solve(N))

Submission status: Accepted

Solution code:
def mm(n):
	global S
	if n==0:
		S=0
	elif n%2==0:
		mm(n/(-2))
		S=S*10
	elif n==1:
		S=1
	elif n%2==1:
		mm((n-1)/(-2))
		S=S*10+1

import sys
sys.setrecursionlimit(10000)
N=int(input())
mm(N)
print(S)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

N = ni()

if N==0:
  print(0)

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

ans = ''
i = 0
if(n == 0):
    print(0)
    exit()
while(abs(n) > 1):
    if(n % 2 ** (i+1) == 0): ans += '0'
    else:
        ans += '1'
        n -= (-2) ** i
    i += 1

print(ans[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C
N = int(input())

data = N
if data == 0:
    re = '0'
else:
    re = ''

    while True:
        if data % 2 == 1:
            data -= 1 #data // abs(data) # 1加算・減算
            re = '1' + re
        else:
            if data // -2 != 0:
                re = '0' + re
            else:
                break
        data = data // -2
    
print(re)

Submission status: Accepted

Solution code:
n = int(input())
tmp = int("1010101010101010101010101010101010", 2)
print(format(tmp ^ (tmp + n), 'b'))

Submission status: Accepted

Solution code:
def solve(N):
    if N == 0:
        return '0'
    if N == 1:
        return '1'

    if N % 2 == 0:
        return '0'+solve(N//-2)
    if N % 2 ==1:
        return '1'+solve((N-1)//-2)

print(solve(int(input()))[::-1])

Submission status: Accepted

Solution code:
N = int(input())

if N<0:
  negative = True
elif N==0:
  print(0)
  exit()
else:
  negative = False

N = abs(N)

a = bin(N)
a = a[2:]
a = [int(i) for i in a]
a.reverse()
a.extend([0,0,0,0,0,0])

for i,num in enumerate(a[-2::-1]):
  digit = len(a)-2-i
  if digit % 2:
    a[digit+1] += num

if negative:
  for i,num in enumerate(a[-2::-1]):
    digit = len(a)-2-i
    a[digit+1] += num


for i,num in enumerate(a):
  while a[i]>1:
    a[i] -= 2
    if a[i+1]:
      a[i+1] -= 1
    else:
      a[i+1] += 1
      a[i+2] += 1

flag = 0
for i in a[::-1]:
  if i == 1:
    flag = i
  if flag:
    print(i,end='')

Submission status: Accepted

Solution code:
N = int(input())
s = ""
while True:
    p = N // (-2)
    q = N % (-2)
    if N < 0 and q != 0:
        p += 1
        q = 1
    if N > 0 and q != 0:
        p += 1
        q = 1

    s += str(q)
    if p == 0:
        break

    N = p

print(s[::-1])

Submission status: Accepted

Solution code:
a=int(input())
sum=0
s=''

if a!=0:
    while(a!=1):
        if a%(-2)==-1:
            s=s+'1'
            a=a-1
            a=a/-2
        else:
            s = s + '0'
            a=a/-2
    s=s+'1'
    for i in range(len(s)):
        print(s[len(s)-1-i],end='')
    print()
else:
    print(0)

Submission status: Accepted

Solution code:
num = int(input())

def to_negative_base(n, neg_base):
    if n == 0:
        return 0

    converted = ""
    while n != 0:
        # remainder = (n % neg_base)
        remainder = n - neg_base * (n // neg_base)
        
        n = n // neg_base

        if remainder < 0:
            remainder += (-neg_base)
            n += 1

        converted = str(remainder) + str(converted)

    return converted

print(to_negative_base(num, -2))

Submission status: Accepted

Solution code:
import math

n = int(input())
s = str(bin(n))[2:]
p = 0
if n >= 0:
    while 1:
        s = str(bin(n))[2:]
        ls = len(s)
        lsp = ls - p - 1
        if ls <= p:
            break
        if p % 2 == 0:
            p += 1
            continue
        if s[lsp] == '0':
            p += 1
            continue
        p += 1
        n += 2**p
else:
    n = abs(n)
    while 1:
        s = str(bin(n))[2:]
        ls = len(s)
        lsp = ls - p - 1
        if ls <= p:
            break
        if p % 2 == 1:
            p += 1
            continue
        if s[lsp] == '0':
            p += 1
            continue
        p += 1
        n += 2**p
print(str(bin(n))[2:])

Submission status: Accepted

Solution code:
memo=-1
n = int(input())
if n==0: 
    print("0")
    exit()
while n != 0:
    if n>0:
        i=1
        j=0
        while i<n:
            i|=i<<2
            j+=2
        n-=1<<j;
    else:
        i=2
        j=1
        while i<abs(n):
            i|=i<<2
            j+=2
        n+=1<<j;
    if memo != -1:
        for i in range(memo-j-1):
            print("0",end="")
    print("1",end="")
    memo=j
for i in range(memo):
    print("0",end="")
print("")

Submission status: Accepted

Solution code:
N = int(input())
if N >= 0:
  if N == 0:
    print(0)
  elif N == 1:
    print(1)
  else:
    s = 2
    j = 2
    i = 1
    while s + j**2 <= N:
      i += 1
      s += j**2
      j*= 2
  
    k = 2 * i + 1
    a  = bin(int('10'*i, 2)^(N-s))[2:]
    if len(a) < k-1:
      a = '0'*(k-1-len(a)) + a
    print('1' + a)
else:
  s = -1
  j = -2
  i = 1
  while N <= s + j:
    s += j
    j *= 4
    i += 1
  k = 2 * i
  print(bin(int('10'*i, 2)^(N-(s+j)-1))[2:])

Submission status: Accepted

Solution code:
a=int(input())
sum=0
s=''
'''if a<0:
    b = abs(a)
    if b%2==1:
        b=b+1
        print(str(bin(b))[2:-1]+'1')
    else:
        print(str(bin(b))[2:-1])'''
if a!=0:
    while(a!=1):
        if a%(-2)==-1:
            s=s+'1'
            a=a-1
            a=a/-2
        else:
            s = s + '0'
            a=a/-2
    s=s+'1'
    for i in range(len(s)):
        print(s[len(s)-1-i],end='')
    print()
else:
    print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect_left
def inpl(): return list(map(int, input().split()))

N = int(input())
A = []
B = []
for i in range(2**16):
    A.append(int(("0{}"*16).format(*list(bin(i)[2:].zfill(16))), 2))
for i in range(2**16):
    B.append(-int(("{}0"*16).format(*list(bin(i)[2:].zfill(16))), 2))

for j, b in enumerate(B):
    i = bisect_left(A, N-b)
    if i == len(A):
        continue
    a = A[i]
    if a+b == N:
        ans = [""]*32
        ans[::2] = list(bin(j)[2:].zfill(16))
        ans[1::2] = list(bin(i)[2:].zfill(16))
        print(int("".join(ans)))
        break

Submission status: Accepted

Solution code:

# cook your dish here
import bisect
n=int(input())

if n == 0:
    print(0)
else:
    p = [1]
    m = []
    ps = 5
    ms = 2
    w = 4
    while w<abs(n)*4:
        p.append(ps)
        m.append(ms)
        w = w *4
        ps += w
        ms += w//2
    #print(p)
    #print(m)
    ass =[]
    
    while n != 0:
        if n > 0:
            jkl = bisect.bisect_left(p,n)
            ass.append(jkl*2)
            n -=4**jkl
        if n < 0:
            n = (-1)*n
            jkl = bisect.bisect_left(m,n)
            ass.append(jkl*2+1)
            n = n*(-1)
            n += (4**jkl)*2
    ans = 0
    for i in range(len(ass)):
        ans += 10**ass[i]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

bin=[]
p = ['00','10','01','11']
m = ['00','11','01','10']
ans=[]
if N < 0:
    N = -1*N
    minus = True
else:
    minus = False
if N == 0:
    print(0)
else:
    while(N != 0):
        n = N % 4
        N = N // 4
        if minus:
            ans.append(m[n])
            if n == 3: N += 1
        else:
            ans.append(p[n])
            if n == 2 or n == 3: N += 1
    bin.append(n)
    ans ="".join(ans)
    ans = ans[::-1]
    print(ans[ans.find('1'):])

Submission status: Accepted

Solution code:
N = int(input())

if N<0:
  negative = True
elif N==0:
  print(0)
  exit()
else:
  negative = False

N = abs(N)

a = bin(N)
a = a[2:]
a = [int(i) for i in a]
a.reverse()

if len(a)%2 == 0 and a[-1]==1:
  a.append(0)
for i,num in enumerate(a[-2::-1]):
  digit = len(a)-2-i
  if digit % 2:
    a[digit+1] += num
  #print('digit: ', digit, 'num: ', num,  '\t', a)


a.append(0)
if negative:
  for i,num in enumerate(a[-2::-1]):
    digit = len(a)-2-i
    a[digit+1] += num


for i,num in enumerate(a):
  while a[i]>1:
    if i < len(a)-1:
      a.append(0)
      a.append(0)
    a[i] -= 2
    if a[i+1] > 0:
      a[i+1] -= 1
    else:
      a[i+1] += 1
      a[i+2] += 1

flag = 0
for i in a[::-1]:
  if i == 1:
    flag = i
  if flag:
    print(i,end='')

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
    print(0)
    exit()
s=list(str(bin(n)))[2:][::-1]
t=[0]*(len(s)+2)
for i in range(len(s)):
    if s[i]=="1":
        if n>=0:
            if i%2==0:
                t[i]+=1
            else:
                t[i]+=1
                t[i+1]+=1
        else:
            if i%2==0:
                t[i]+=1
                t[i+1]+=1
            else:
                t[i]+=1
    else:
        pass
for i in range(len(t)):
    if t[i]==2:
        if i%2==1:
            t[i]=0
            if t[i+1]>0:
                t[i+1]-=1
            else:
                t[i+1]+=1
                t[i+2]+=1
        else:
            t[i]=0
            t[i+1]+=1
            t[i+2]+=1
t=t[::-1]
i=0
while t[i]==0:
    i+=1
print("".join(map(str,t[i:])))

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
n=li[0]
ans = 0

def asd(x):
    global ans
    if x>0:
        for i in range(0,35):
            max = 0
            l=0
            for j in range (0,i,2):
                max += pow(-2,j)
            if max >= x:
                ans += pow(10,i-1)
                #print(pow(-2,i-1))
                return asd(x-(pow(-2,i-1)))
                #asd(x-pow(-2,i-1))
    elif x<0:
        for i in range(0,35):
            min =0
            for j in range (1,i,2):
                min += pow(-2,j)
            if min <= x:
                ans += pow(10,i-1)
                #print(pow(-2,i-1))
                return asd(x-(pow(-2,i-1)))
                
                


    elif x==0:
        return 0
asd(n)
print(ans)

Submission status: Accepted

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

d = N
ans = []
while d != 0:
    d, m = divmod(d, -2)
    if m == -1:
        d += 1
    ans.append(abs(m))
print(*reversed(ans), sep='')

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
    print(0)
else:
    d = 0
    pows = [(0, 1)]
    for i in range(1, 50):
        a, b = pows[i-1]
        if i%2 == 1:
            min_ = b-2**(i+1)+1
            pows.append((min_, min_+2**i-1))
        else:
            max_ = a+2**(i+1)-1
            pows.append((max_-2**i+1, max_))
    pows[0] = (1, 1)
    # for p in pows: print(p)

    ans = ''
    d = len(pows)-1
    for p in pows[::-1]:
        pmin, pmax = p
        if n >= pmin and n <= pmax:
            ans += '1'
            n -= (-2)**d
            # print((-2)**d)
        else:
            ans += '0'

        d -= 1
    print(ans.lstrip('0'))

Submission status: Accepted

Solution code:
import math
def Base_10_to_m2(n):
  if int(n / (-2)) or n < 0:
    a = math.ceil(n / (-2))
    ans.append(n - a * (-2))
    return Base_10_to_m2(a)
  ans.append(n - math.ceil(n / (-2)) * (-2))
  return ans

n = int(input())
ans = []
print("".join(map(str, Base_10_to_m2(n)[::-1])))

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

n = int(input())

v = []

tmp_n = n
plus = 0

if tmp_n < 0:
    plus = 1
    tmp_n *= -1

while tmp_n > 0:
    v.append(tmp_n & 1)
    tmp_n = tmp_n >> 1

r = [0 for _ in range(len(v) + 10)]
for i in range(len(v)):
    if i % 2 == plus:
        r[i] += v[i]
    else:
        r[i] += v[i]
        r[i + 1] += v[i]

for i in range(len(r)):
    while (r[i] >= 2 and r[i + 1] >= 1):
        r[i] -= 2
        r[i + 1] -= 1
    while r[i] >= 2:
        r[i + 1] += 1
        r[i + 2] += 1
        r[i] -= 2

started = False
res = ""
for i in range(len(r)):
    idx = len(r) - 1 - i
    if r[idx] == 1:
        res = res + "1"
        started = True
    elif started == True:
        res = res + "0"

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
A = [0]*100
B = [0]*100

if n == 0:
    print(0)
    sys.exit(0)
if n == 1:
    print(1)
    sys.exit(0)
A[0] = (0, 1)
B[0] = (1, 1)
i = 1
v = -2
while(True):
    if v < 0:
        A[i] = (A[i-1][0]+v, A[i-1][1])
        B[i] = (A[i-1][0]+v, A[i-1][1]+v)
    else:
        A[i] = (A[i-1][0]  , A[i-1][1]+v)
        B[i] = (A[i-1][0]+v, A[i-1][1]+v)
    if A[i][0] <= n and n <= A[i][1]:
        break
    i += 1
    v *= -2

S = ''
for j in range(i, -1, -1):
    if B[j][0] <= n and n <= B[j][1]:
        S += '1'
        n -= v
    else:
        S += '0'
    v /= -2
print(S)

Submission status: Accepted

Solution code:
def f(n):
    n = int(n)
    if n in [0, 1]:
        return str(n)
    return f((n - (abs(n) % 2)) / -2) + str(abs(n) % 2)

print(f(int(input())))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
if n == 0:
  print(0)
  sys.exit()
s = ""
while n!= 0:
  if ((n<0 and (-n)%2==0) or (n>0 and n%2==0)):
    s = "0" + s
  else:
    s = "1" + s
    n-=1
  n/=-2
print(s)

Submission status: Accepted

Solution code:
n = int(input())
m = n
s = ''

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

while m != 0 :

   if m%2 == 0 :
      s = '0' + s
      m = m / (-2)
   else :
      s = '1' + s
      m = (m-1) / (-2)

print(s)

Submission status: Accepted

Solution code:
N = int(input())
base = 1
pos = 0
ans = ''
while N != 0:
    if abs(N) & (1 << pos):
        N -= base
        ans += '1'
    else:
        ans += '0'
    pos += 1
    base *= -2
# corner case!
if ans == '':
    print(0)
else:
    print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())
str2N = bin(abs(N))[2:]
S = ''
inc = 0
for i, s in enumerate(str2N[::-1]):
  S += str((int(s) + inc) % 2)
  if N > 0:
    if i % 2 == 0:
      inc = (int(s) + inc) // 2
    else:
      inc = 1 if (int(s) + inc) else 0
  else:
    if i % 2 == 0:
      inc = 1 if (int(s) + inc) else 0
    else:
      inc = (int(s) + inc) // 2
S += str(inc)
if abs(N) > 0:
  S = S[::-1][S[::-1].find('1'):]
  if N > 0:
    if len(S) % 2 == 0:
      S = '1' + S
  else:
    if len(S) % 2 != 0:
      S = '1' + S
  print(S)
else:
  print('0')

Submission status: Accepted

Solution code:
import sys

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

walist=[0]*50
walist[0]=1
walist[1]=-2
for i in range(1,25):
    walist[2*i]=walist[2*i-2]+2**(2*i)
    walist[2*i+1]=walist[2*i-1]-2**(2*i+1)


    


def near(k):
    if k>=0:
        for i in range(16):
            if 2**i<=k<=walist[2*i]:
                return 2*i
            if 2**(2*i)>=k:
                return 2*i
    else:
        for i in range(16):
            if walist[(2*i)+1]<=k<=-2**((2*i)+1):
                return 2*i+1
            if -2**((2*i)+1)<=k:
                return 2*i+1


ANSSTR=[0]*50

while True:
    k=near(N)
    ANSSTR[k]=1
    N=N-(-2)**k
    if N==0:
        break

for i in range(49,-1,-1):
    if ANSSTR[i]==1:
        break

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

Submission status: Accepted

Solution code:
def c_base_minus2_number(N):
    # 10進数を他の(正の)進数表記に変換するときと同様
    def negabinary(n):  # nを-2進数(文字列)で表現する
        if n == 0:
            return '0'
        digits = []
        while n != 0:
            # Pythonにおいて a % b の符号はbの符号に一致する
            n, remainder = divmod(n, -2)
            if remainder < 0:
                n, remainder = n + 1, remainder + 2  # 余りは非負とする
            digits.append(str(remainder))
        return ''.join(digits[::-1])

    ans = negabinary(N)
    return ans

N = int(input())
print(c_base_minus2_number(N))

Submission status: Accepted

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

Submission status: Accepted

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

s = s[::-1]
if s == "": s = "0"
print(s)

Submission status: Accepted

Solution code:
N = int(input())

def g(n):
    b = format(-n, 'b')
    ret = [0] * (len(b) + 2)
    for i, x in enumerate(reversed(b)):
        if x == '0': continue
        if i & 1:
            if ret[i]:
                ret[i] = 0
                ret[i+2] = ret[i+1] = 1
            else:
                ret[i] = 1
        else:
            if ret[i]:
                ret[i] = 0
            else:
                ret[i] = ret[i + 1] = 1
    ret = ret[::-1]
    return ret[ret.index(1):]

def f(n):
    b = format(n, 'b')
    ret = [0] * (len(b) + 2)
    for i, x in enumerate(reversed(b)):
        if x == '0': continue
        if i & 1:
            if ret[i]:
                ret[i] = 0
            else:
                ret[i] = ret[i + 1] = 1
        else:
            if ret[i]:
                ret[i] = 0
                ret[i+2] = ret[i+1] = 1
            else:
                ret[i] = 1
    ret = ret[::-1]
    return ret[ret.index(1):]

if N == 0:
    print(0)
elif N > 0:
    print("".join([str(x) for x in f(N)]))
else:
    print("".join([str(x) for x in g(N)]))

Submission status: Accepted

Solution code:
N = int(input())

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

ans = ""
while(N != 0):
    div = N // -2
    rem = N % -2
    if rem == -1:
        div += 1
        rem = 1
    N = div
    ans = str(rem) + ans
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N==0:
    print(0)
    exit()
ans = ""
p = True
while N!=0:
    d, m = divmod(N, 2)
    if p:
        N -= m
    else:
        N += m
    ans = str(m) + ans
    N //= 2
    p = not p
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

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

ans = ""

if N == 0:
    ans += '0'
while abs(N) >= 1:
    if N % (-2) == -1:
        N = N // (-2) + 1
        ans += '1'
    elif N % (-2) == 0:
        N = N // (-2)
        ans += '0'
ans = ans[::-1]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
if n==0:
    print("0")
else:
    while n!=0:
        r=n%(-2)
        n=n//(-2)
        if r<0:
            r+=(2)
            n+=1
        a.append(r)
a=a[::-1]
print(*a,sep='')

Submission status: Accepted

Solution code:
N=int(input())
S = []
for i in range(16):
  if   N%4==0: S.append('00'); N-=0
  elif N%4==1: S.append('01'); N-=1
  elif N%4==2: S.append('10'); N+=2
  else       : S.append('11'); N+=1
  N = N//4
  if N == 0: break
ans=''.join(reversed(S))
if ans[0]=='0': ans = ans[1:]
print(ans)