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 math
n = int(input())
x = []

if n == 0:
    print(0)
else:
    if n > 0:
        a = math.ceil(math.log2(n * 3 + 1) / 2) 
        b = 2 * a - 1
        x = [[]] * (b)
    else:
        a = math.ceil(math.log2((-3 * n + 2) / 2) / 2)
        b = 2 * a
        x = [[]] * (b)
    while n != 0:
        if n > 0:
            a = math.ceil(math.log2(n * 3 + 1) / 2) 
            b = 2 * a - 1 
            n = n - (2) ** (b-1)
            x[-b] = "1"  
        else:
            a = math.ceil(math.log2((-3 * n + 2) / 2) / 2)
            b = 2 * a
            n = n - (-2) ** (b-1)
            x[-b] = "1"
x_replace = ["0" if i != "1" else i for i in x]
x_replace = "".join(x_replace)
print(x_replace)

Submission status: Accepted

Solution code:
n = int(input())
m2 = []

if n == 0:
    print(0)
    
while n != 0:
    if n % -2 != 0:
        m2.append('1')
        n = n // -2 + 1
    else:
        m2.append('0')
        n = n // -2
        
m2.reverse()
print(''.join(map(str, m2)))

Submission status: Accepted

Solution code:
n = int(input())

ans = ''

# 10は適当
for i in range(1000):
  if n % pow(2, i+1) == 0: # 割れたら 0になる
    ans += '0'
  else: # 割れなかった時
    ans += '1'
    n = n - pow(-2, i)
  if n == 0:
    break
print(ans[::-1])

Submission status: Accepted

Solution code:
import math
import sys

N = int(input())
if N == 0:
    max = 1
else:
    max = math.ceil(math.log(abs(N), 2)) + 3

result = []
numerator = N
for i in range(0, max):
    if numerator % (math.pow(2, i + 1)) == 0:
        result.append(str(0))
    else:
        result.append(str(1))
        numerator -= math.pow(-2, i)

    if numerator == 0:
        break
result.reverse()
print("".join(result))

Submission status: Accepted

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

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

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

    else:
        ans += '0'
    i += 1
    
print(int(ans[::-1]))

Submission status: Accepted

Solution code:
n = int(input())
binary = []
flag = 0

if n == 0:
    print(0)
    flag = 1
    
while n != 0:
    if n % -2 != 0:
        binary.append('1')
        n = n // -2 + 1
    else:
        binary.append('0')
        n = n // -2

binary.reverse()

if flag == 0:
    print(''.join(binary))

Submission status: Accepted

Solution code:
n = int(input())

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

t   = 0
idx = 0
max = 0

if n > 0 :
    while True:
        max = idx
        t   += 2**idx
        idx  = idx + 2
        #print(t)
        if t >= n :
            break
else:
    idx = 1
    while True:
        max = idx
        t   += -2**idx
        idx  = idx + 2
        #print(t)
        if t <= n :
            break

#print(t,max)

ans = ''
s   = 0
for i in range(max+1):
    idx = 0

    sidx = (i-1)//2
    t = 1

    if i > 0 :
        start = 1
        for j in range(sidx):
            t *= 4
            start += t
    else:
        start = 0
    
    t = (n - start)/(2**i)

    if t - (n - start)//(2**i)  > 0 :
        t = (n - start)//(2**i) + 1
    else :
        t = (n - start)//(2**i)   

    if t % 2 == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans

        if i % 2 == 0 :
            s += 2**i
        else:
            s -= 2**i

print(ans)

# +) 1 4 16  64 258 1024
# -) 2 8 32 128 512 2048

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:
N=int(input())
if N==0:
    print(0)
else:
    P=0
    M=0
    A=[0 for i in range(33)]
    for j in range(33):
        if N==0:
            break
        else:
            for i in range(33):
                if i%2==0:
                    if 0<=N and N<=(((-2)**i)+P):
                        break
                    else:
                        P+=(-2)**i
                elif i%2==1:
                    if N<=0 and (((-2)**i)+M)<=N:
                        break
                    else:
                        M+=(-2)**i
            A[i]=1
            N-=(-2)**i
            P=0
            M=0
    A=A[::-1]
    ans=0
    for k in range(33):
        ans+=A[k]*(10**(32-k))
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
binarys = []
flag = 0

if N == 0:
    print(0)
    flag = 1
    
while N != 0:
    if N % -2 != 0:
        binarys.append('1')
        N = N // -2 + 1
    else:
        binarys.append('0')
        N = N // -2

binarys.reverse()

if flag == 0:
    print(''.join(binarys))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
if n==0:
    print(0)
    exit()
s = []

while n != 0:
    x = n%-2
    if x<0:
        s.append("1")
        n = n//-2 +1
    else:
        s.append("0")
        n = n//-2
s.reverse()
print("".join(s))

Submission status: Accepted

Solution code:
n = int(input())

ans = []
while n != 0:
    if n % -2 == -1:
        n -= 1
        ans += ['1']
    else:
        ans += ['0']
    n //= -2
ans.reverse()
if len(ans) == 0:
    print(0)
else:
    print(''.join(ans))

Submission status: Accepted

Solution code:
N = int(input())

res = ""
while True:
    if N%2 == 0:
        res = "0" + res
        if N == 0:
            break
        N = -(N//2)
    else:
        res = "1" + res
        if N != 1:
            N = -((N-1)//2)
        else:
            break

print(res)

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print('0')
    exit()
res = []
for i in range(32):
    digit = (-2) ** i
    if N % (digit * (-2)) != 0:
        N -= digit
        res.append('1')
    else:
        res.append('0')
while res[-1] == '0':
    res.pop()
print(''.join(res[::-1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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
print(ans if ans!="" else 0)

Submission status: Accepted

Solution code:
N = input()

ans = ""

while True:
  if abs(N) % 2 == 1:
    ans += "1"
    N -= 1
  else:
    ans += "0"
  N /= -2
  if N == 1:
    ans += "1"
    print(ans[::-1]) 
    break

  if N == 0:
    print (0)
    break

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())

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

ans = []
x = 2
i = 0
while n != 0:
    if n%x!=0:
        ans.append(1)
        n = n - (-2)**i
    else:
        ans.append(0)    
    i += 1
    x *= 2 
print(''.join([ str(x) for x in ans[::-1]]))

Submission status: Accepted

Solution code:
import sys
N = int(input())
result = ""
if N == 0:
    print(0)
    sys.exit()
while N != 1:
    if N == -2:
        N = 10
        break
    result += str(N%2)
    if N%2:
        N = N//(-2) +1
    else:
        N = N//(-2)
print(str(N) + result[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())

LIST2=[1]
LIST2X=[-2]

N=1
for i in range(1,30):
    N=N+4**i
    LIST2.append(N)
N=-2
for i in range(1,30):
    N=N-2*4**i
    LIST2X.append(N)



LIST=[0]*60

def nex(N):
    if N>0:
        for i in range(30):
            if N<=LIST2[i]:
                break
        LIST[i*2]+=1
        return N-(-2)**(i*2)

    if N<0:
        for i in range(30):
            if N>=LIST2X[i]:
                break
        LIST[i*2+1]+=1
        return N-(-2)**(i*2+1)

while x!=0:
    x=nex(x)
    #print(x)

for i in range(59,-1,-1):
    if LIST[i]==1:
        break

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

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:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def n_based(n:int, base:int) -> str:
    if n == 0:
        return "0"
    
    ans = ""
    res = n
    
    while abs(res) > 0:
        q = res%base
        if q>=0:
            ans = str(q) + ans
            res //= base
        else:
            q += abs(base)
            ans = str(q) + ans
            res //= base
            res += 1
        
    return ans

n = ni()
print(n_based(n,-2))

Submission status: Accepted

Solution code:
import math

# print("{}/{}={} %{}".format(-123, 10, -123/10, -123 %10))
n = int(input())
if n == 0:
    print(0)
    exit()
out = ""
i = 0
while n != 0:
    if n % -2 != 0:
        out = str(- (n % -2)) + out
        # print("n:{} div:{}=(-2)^{}".format(n, (-2) ** i, i))
    else:
        out = str(- (n % -2)) + out

    # 12 -> 2 + 10^1, -12 -> 8 + 2*(-10)^1
    if n > 0:
        n = int(n / (-2))
    else:
        n = math.ceil(n / (-2))
    i += 1
print(out)

Submission status: Accepted

Solution code:
import math

n = int(input())
if n == 0:
    print(0)
    exit()
out = ""
i = 0
while n != 0:
    if n % -2 != 0:
        out = str(- (n % -2)) + out
        # print("n:{} div:{}=(-2)^{}".format(n, (-2) ** i, i))
    else:
        out = str(- (n % -2)) + out

    # 123->100, -123->-100
    if n > 0:
        n = int(n / (-2))
    else:
        n = math.ceil(n / (-2))
    i += 1
print(out)
"""
tmp = 1
digit = 0
while tmp < n:
    tmp *= 4
    digit += 1
number = [0 for i in range(digit)]
print(number)
tmp = n
for i in range(digit):
    if 0 < tmp % 4 < 4:
        number[i] = tmp % 4
        tmp = int(tmp / 4)
"""

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
    print(0)
    exit()
out = ""
i = 0
while n != 0:
    if n % -2 != 0:
        out = str(- (n % -2)) + out
        n += n % -2
        # print("n:{} div:{}=(-2)^{}".format(n, (-2) ** i, i))
    else:
        out = str(n % 2) + out
    n = int(n / (-2))
    i += 1
print(out)
"""
tmp = 1
digit = 0
while tmp < n:
    tmp *= 4
    digit += 1
number = [0 for i in range(digit)]
print(number)
tmp = n
for i in range(digit):
    if 0 < tmp % 4 < 4:
        number[i] = tmp % 4
        tmp = int(tmp / 4)
"""

Submission status: Accepted

Solution code:
n=int(input())
flg = 0
if n < 0:
    n *= -1
    flg = 1
l=list(map(int,str(bin(n))[2:]))
for i in range(1,len(l)+3): 
    try:
        if l[-i] == 2:
            l[-i] = 0
            if i == len(l):
                l.insert(0,1)
            else:
                l[-(i+1)]+=1
        if i%2==flg and l[-i]==1:
            if i == len(l):
                l.insert(0,1)
            else:
                l[-(i+1)]+=1
    except:
        pass
s = ''.join([str(x) for x in l])
print(s)

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//2)
ans=int(ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
li = []
res = n % (-2)
ans = n // (-2)
ans1 = n
if res != 0:
    res = ans1 - (-2) * (ans + 1)
    ans = ans + 1
ans1 = ans
li.append(res)
p = 0
if ans == 0 or ans == 1:
    p = 1
    if ans == 1:
      li.append(ans)
while p == 0:
  res = ans % (-2)
  ans = ans // (-2)
  if res != 0:
      res = ans1 - (-2) * (ans + 1)
      ans = ans + 1
  ans1 = ans
  li.append(res)
  if ans == 0 or ans == 1:
    p = 1
    if ans == 1:
      li.append(ans)
li = [str(n) for n in li]
pr = ""
for i in range(len(li)):
  pr += li[-1-i]
print(pr)

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    ans = '0'
else:
    ans = ''
    while N != 0:
        ans = str(N % 2) + 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:
import sys
from math import ceil

N = int(input())
ans = []

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

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

Submission status: Accepted

Solution code:
def 解():
    iN = int(input())
    ans = []
    while True:
        if iN in {1,0}:
            ans.append(iN)
            break
        if iN < 0 :
            if iN == -1:
                iN = 1
                ans.append(1)
            else:
                iN *= -1
                ans.append(iN % 2)
                if iN % 2 :
                    iN //= 2
                    iN += 1
                else:
                    iN //= 2

        else:
            ans.append(iN % 2)
            iN //= 2
            iN *= -1
    print("".join(map(str,ans[::-1])))
解()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
i=0

if(n==0):
    print(0)
elif(n>0):
    tmp=1
    mainasu=0
    i=1
    while(tmp < n):
        tmp+=4**i
        mainasu-=2*4**(i-1)
        i+=1
    x=bin(n-mainasu)
    for i in range(2,len(x)):
        if(i%2==1):
            if(x[i]=="1"):
                print("0",end="")
            else:
                print("1",end="")
        else:
            print("{}".format(x[i]),end="")
    print()
else:
    tmp=-2
    mainasu=1
    i=1
    while(n < tmp):
        tmp-=2*4**i
        mainasu+=4**i
        i+=1
    x=bin(mainasu-n)
    for i in range(2,len(x)):
        if(i%2==1):
            if(x[i]=="1"):
                print("0",end="")
            else:
                print("1",end="")
        else:
            print("{}".format(x[i]),end="")
    print()

Submission status: Accepted

Solution code:
N = input()
res = []
while N != 0:
	if N % (-2) == 0:
		res.append("0")
	else:
		res.append("1")
		N -= 1
	N //= (-2)
if len(res) == 0:
	res.append("0")
print "".join(reversed(res))

Submission status: Accepted

Solution code:
N=int(input().strip())
i=0
S=""
if N==0:
    print(0)
else:
    while N!=0:
        if N%(2**(i+1))==0:
            sp="0"
        else:
            sp="1"
        S=sp+S
        N=N-(int(sp)*((-2)**i))
    #    print(N)
        i=i+1
#        print(sp)
    print(int(S))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

    if N == 0:
        print(0)
        return

    dp = [(0, 0)] * 32
    dp[0] = (0, 1)
    for i in range(1, 32):
        if i % 2 == 0:
            a = 2 ** i
            dp[i] = (dp[i - 1][0], dp[i - 1][1] + a)
        else:
            a = -(2 ** i)
            dp[i] = (dp[i - 1][0] + a, dp[i - 1][1])

    ans = ""
    total = 0
    for i in range(31, 0, -1):

        l, r = dp[i - 1]
        if i % 2 == 0:
            a = 2 ** i
        else:
            a = -(2 ** i)

        rest = N - total

        if l + a <= rest <= r + a:
            total += a
            ans += "1"
        else:
            ans += "0"

    if N - total == 1:
        ans += "1"
    else:
        ans += "0"
    print(ans.lstrip("0"))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def base2_number(n):
    result = ""
    while True:
        rem = n % 2
        if rem:
            n -= 1
        n = n // -2
        result += str(abs(rem))
        if n == 0:
            break
    return int(result[::-1])
n = int(input())
print(base2_number(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
 
def minus_2(n):
    ans = ''
    if n == 1:
        ans += '1'
    elif n == 0:
        ans += '0'
    else:
        while n != 1:
            if n % 2 == 0:
                ans += '0'
            else:
                ans += '1'
            n = math.ceil(n/-2)
        ans += '1'
        ans = ans[::-1]
        
    return ans
 
print(minus_2(N))

Submission status: Accepted

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

Submission status: Accepted

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

result.reverse()
for i in range(len(result)):
    nishin = nishin+str(result[i])
print(nishin)

Submission status: Accepted

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

    print(t[::-1])

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print('0')
else:
    k = 1
    ans = []
    while(True):
        if N % ((-2) ** k) == 0:
            ans.append('0')
        else:
            ans.append('1')
            N -= (-2) ** (k - 1)
        if N == 0:
            break
        else:
            k += 1
    print(''.join(ans[::-1]))

Submission status: Accepted

Solution code:
n = int(input())
k = 1
kotae = []
kotae2 = []

if n != 0:
    while n != 0:
        if n % ((-2) ** k) == 0:
            kotae.append(0)
        else:
            kotae.append(1)
            n = n - ((-2) ** (k - 1))
        k = k + 1

    for i in kotae[::-1]:
        kotae2.append(str(i))

    print("".join(kotae2))
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
a=n
while a!=0:
    ans.append(a%2)
    a=(a-a%2)//(-2)
if ans==[]:
    ans=[0]
print(''.join(map(str, reversed(ans))))

Submission status: Accepted

Solution code:
N = int(input())

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

if ans == []:
    ans =[0]

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

Submission status: Accepted

Solution code:
n = int(input())
ant = 0
if n == 0:
    ant = 1
ans = ''
for i in range(10000):
    if n == 0:
        break
    if n % 2 ** (i + 1) == 0: 
        ans = '0' + ans
    else:
        n -= (-2)**i
        ans = '1' + ans
if ant == 0:
    print(ans)
else:
    print('0')

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())
S=""
for i in range(50):
    if N%(-2)==0:
        S="0"+S
    else:
        S="1"+S
        N-=1
    N=N//(-2)
print(int(S))

Submission status: Accepted

Solution code:
n=input()
s=[]
n=int(n)
i=0
while n!=0:
  if n%2**(i+1)==0:
    s.append("0")
  else:
    s.append("1")
    n-=(-2)**i
  i+=1
s.reverse()
if s==[]:
  s=["0"]
print("".join(s))

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print('0')
    exit()
check = 1
now = 0
ans = ''
count = 1
while True:
    check *= 2
    a = N%check
#    print(a,count,now)
    if now == N:
        break    
    else:
        if (a-now)%check != 0:
            ans = ans + '1'
            now += count
        else:
            ans = ans + '0'
        count *= -2

print(ans[::-1])

Submission status: Accepted

Solution code:
def m():
    n = int(input())
    L = 32
    a = [0] * L
    b = [0] * L
    b[0], b[1] = 1, -2
    ans = ["0"] * L
    for i in range(L):
        a[i] = (-2) ** i

    for i in range(2, L):
        b[i] = a[i] + b[i-2]
    
    def solve(p):
        if p == 0:
            return
        if p < 0:
            for j in range(1, L, 2):
                if p >= b[j]:
                    p -= a[j]
                    ans[j] = "1"
                    solve(p)
                    break
        else:
            for j in range(0, L, 2):
                if p <= b[j]:
                    p -= a[j]
                    ans[j] = "1"
                    solve(p)
                    break
    solve(n)
    ans.reverse()
    return int("".join(ans))


print(m())

Submission status: Accepted

Solution code:
n=int(input())
def isdig(n):
  if n>=0:
    digit=0
    while n>2**digit:
      n-=2**digit
      digit+=2
  else:
    digit=1
    while n<-2**digit:
      n+=2**digit
      digit+=2
  return digit
x=["0"]*(isdig(n)+1)
while n!=0:
  digit=isdig(n)
  if digit%2==0:
    n-=2**digit
  else:
    n+=2**digit
  x[digit]="1"
x.reverse()
print("".join(x))

Submission status: Accepted

Solution code:
N = int(input())
result = []
def change(num):
    if num != 0:
        div = num // (-2)
        mod = num % (-2)
        if mod == -1:
            div += 1
            mod = 1
        result.append(mod)
        if div == 1:
            result.append(div)
            print(''.join(map(str, result[::-1])))
        else:
            n = div
            change(n)
    else:
        print(0)
change(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#10進数Nを逆2進数リストに変換する関数
def change_2r(N):
    if N==0:
        return [0]
    list=[]
    while N>=2:
        list.append(N%2)
        N=int((N-N%2)/2)
    list.append(1)
    return list
  
#逆2進数リストNのi-1桁目(N[i])へ繰り上がる関数
def moveup(N,i):
    if len(N)<=i:
        N.append(1)
    else:
        if N[i]==0:
            N[i]=1
        elif N[i]==1:
            N[i]=0
            moveup(N,i+1)

N=int(input())
i=0
if N>=0:
    Nlist=change_2r(N)
    while i<len(Nlist):
        if i%2!=0 and Nlist[i]==1:
            moveup(Nlist,i+1)
        i+=1
else:
    N=-N
    Nlist=change_2r(N)
    while i<len(Nlist):
        if i%2==0 and Nlist[i]==1:
            moveup(Nlist,i+1)
        i+=1
        
Nlist.reverse()
print(''.join(map(str,Nlist)))

Submission status: Accepted

Solution code:
def f(N):
    if N == 0 or N == 1:
        return str(N)
    else:
        return f(N // 2 * -1) + str(N % 2)

N = int(input())
print(f(N))

Submission status: Accepted

Solution code:
import sys

N = int(input())

k = 0
S = []
while 1:
    if N % 2 == 0:
        S.append(0)
    else:
        N -= (-1) ** k
        S.append(1)
    N /= 2
    k += 1
    if N == 0:
        break

for i in S[::-1]:
    sys.stdout.write(str(i))
sys.stdout.write('\n')

Submission status: Accepted

Solution code:
N = int(raw_input())
res = []
base = N
x = 1
if base == 0:
    print(0)
else:
    while True:
        if base == 0:
            break
        if base % (2 ** x) != 0:
            res.append(1)
            base -= (-2) ** (x-1)
        else:
            res.append(0)
        x += 1
    print(''.join([str(i) for i in reversed(res)]))

Submission status: Accepted

Solution code:
N = int(input())
anslist = []
i = 0
j = 1
key = 0
while True:
    if N == 0:
        break
    if N % pow(-2, i + 1) != 0:
        anslist.append(1)
        N -= pow(- 2, i)
        key += pow(-2, i)
    else:
        anslist.append(0)
    i += 1
    #print(anslist)
if len(anslist) == 0:
    anslist.append(0)
for i in anslist[::-1]:
    print(i, end = "")
print()

Submission status: Accepted

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

if s=="":
  s="0"

print("".join(s))

Submission status: Accepted

Solution code:
n = int(input())
def divminus2(n):
    if n%2 == 1:
        q = n // -2 + 1
        r = n % 2
    else:
        q = n // -2
        r = 0
    return q,r

ans_list = []
while n != 0:
    q,r = divminus2(n)
    n = q
    ans_list.append(str(r))

ans_list.reverse()
if ans_list == []:
    print("0")
else:
    print("".join(ans_list))

Submission status: Accepted

Solution code:
n = int(input())
def divminus2(n):
    if n%2 == 1:
        q = n // -2 + 1
        r = abs(n % 2)
    else:
        q = n // -2
        r = 0
    return q,r

ans_list = []
while n != 0:
    q,r = divminus2(n)
    n = q
    ans_list.append(str(r))

ans_list.reverse()
if ans_list == []:
    print("0")
else:
    print("".join(ans_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    s = ''
    t = 1
    if n == 0:
        print(0)
        return
    while n != 0:
        a = abs(n % 2)
        s = str(a) + s
        n -= a * t
        n = int(n / 2)
        t *= -1
    print(s)


solve()

Submission status: Accepted

Solution code:
n = int(input())
if n > 0:key = 1
if n < 0:key = 0
lis = []
if n == 0:
  lis.append("0")
while abs(n) >= 1:
  if n % 2 == 1:
    n -= 1
    lis.insert(0,"1")
  else:
    lis.insert(0,"0")
  n = n // (-2)
print("".join(lis))

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(s[::-1])

Submission status: Accepted

Solution code:
N = int(input())

A=[]
n=N

for i in range(32):
    if n % 2 != 0:
        A.append(1)
        n -= 1
    else:
        A.append(0)
        
    n /= -2
    
ret=""
flg=0
for i in range(len(A)-1,-1,-1):
    if A[i] != 0:
        flg = 1
    if flg != 0:
        ret += str(A[i])
    
if ret=="":
    ret = "0"
print (ret)

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())

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

i=0
s=''
while(n!=0):
    if n%(2**(i+1))!=0:
        s+='1'
        n-=(-2)**i
    else:
        s+='0'
    i+=1
print (s[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)
else:
    ans = ""
    while abs(N) > 0:
        mod = N % (-2)
        N //= -2
        N += (mod < 0)
        ans += str(abs(mod))

    print(ans[::-1])

Submission status: Accepted

Solution code:
N = int(input())
B = []
i = 0
if N == 0:
    print(0)
    exit()
while N != 0:
    if N % (2**(i+1)) != 0:
        B.insert(0,1)
        N -= (-2)**i
    else:
        B.insert(0,0)
    #print(B)
    #print(N)
    i += 1
print(''.join(map(str, B)))

Submission status: Accepted

Solution code:
"""
C - Base -2 Number
-2進数を出力する
"""

N = int(input())

num = []
while True:
    quotient = N // (-2)
    mod = N % -2
    
    if mod < 0:
        quotient += 1
        mod = 1
    
    num.append(mod)
    N = quotient

    if quotient == 0:
        break
        
num.reverse()
for n in num:
    print(n, end="")

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
import math

N = int(input())
if N == 0:
    print('0')
    quit()

a = 1
res = ""
while N != 0:
    if N % (2 * a) == 0:
        res = "0" + res
    else:
        res = "1" + res
        N -= a
    a *= -2
print(res)