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())

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = ans[::-1]
if ans == '':
    ans = '0'

print(ans)

Submission status: Accepted

Solution code:
# base -k representation of n
def f(n, k):
    if n == 0:
        return []
    r = n % k
    return f(-(n - r) // k, k) + [r]

N = int(input())
l = f(N, 2)
if l:
    print("".join(map(str, l)))
else:
    print(0)

Submission status: Accepted

Solution code:
ans = ''
n = int(input())
b = 1
while True:
  if n %(-2 * b) == 0:
    ans  = '0' +  ans 
  else:
    ans = '1' +  ans
    n -= b
  if n == 0:
    break
  b *= -2
print(ans)

Submission status: Accepted

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

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

def num_muls(n):
    ans = 0
    while (n >> ans) & 1 == 0:
        ans += 1
    return ans

ans = ''
count = 0

while N != 0:
    m = num_muls(N)
    # print('num_muls, count={}, m={}'.format(count, m))
    if m > 0:
        # print('m!=0', ans, N, count)
        ans = '0'*m + ans
        N //= (2**m)
        count += m
        # print('N={}, count={}'.format(N, count))
    else:
        # print('m==0', ans, N, count)
        ans = '1' + ans
        N -= (-1)**count
        N //= 2
        count += 1
        # print('N={}, count={}'.format(N, count))

print(ans)

Submission status: Accepted

Solution code:
a = int(input())

if a==0:
    print(a)
    quit()
i=0
ans=0
while(a):
    amari = a%-2
    if amari<0:
        amari=1
        ans+=10**i
    a=(a-amari)/-2
    i+=1
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
if a == 0:
    print("0")
else:
    digits = []*10
    base = 1
    i = 0
    while a != 0:
        if a%(base*2) == 0:
            digits.append('0')
        else:
            digits.append('1')
            a -= base
        i += 0
        base *= -2
    print(''.join(digits[::-1]))

Submission status: Accepted

Solution code:
import numpy as np
array=np.array([[0,1]])
cnt=1
N=int(input())
import sys

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

while(1):
    array=np.append(array,np.array([[((-2)**cnt)+np.min(array),((-2)**cnt)+np.max(array)]]),axis=0)
    if array[-1][0]<=N<=array[-1][1]:
        break
    else:
        cnt+=1
for i in range(len(array)-1,0,-1):
    if array[i][0]<=N<=array[i][1]:
        print(1,end="")
        N=N-(-2)**(i)
    else:
        print(0,end="")
print(N)

Submission status: Accepted

Solution code:

N = int(input())
OriN = N

bul = True
cnt = 0
lis = []

while bul:

    if N % (2 ** (cnt + 1)) == 0:
        lis.append(0)

    else:
        lis.append(1)
        N = N - ( (-2) ** cnt )


    now = 0
    for i in range(len(lis)):

        now += lis[i] * ((-2) ** i )

    if now == OriN:
        break

    cnt += 1


#print (lis)

ans = ""
for i in lis:

    ans = str(i) + ans

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
def reversed_bit(N):
    if N == 1:
        return [1]
    elif N == 0:
        return [0]
    elif N % 2 == 0:
        return reversed_bit(N / (-2)) + [0]
    else:
        return reversed_bit((N-1) / (-2)) + [1]
m = ""
for i in range(len(reversed_bit(n))):
    m += str(reversed_bit(n)[i])
print(str(m))

Submission status: Accepted

Solution code:
N = int(input())

dev = -2
ans = ''
Q = N

if Q == 0:
    ans += '0'
    
while Q != 0:

    if Q%dev != 0:
        Q -= 1
        ans = '1' + ans
    else:
        ans = '0' + ans

    Q = Q//dev


print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = ""

if n == 0 : ans ="0"

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
if n==0:print(0)
else:
    a=""
    while n!=0:
        k=n%4
        if k==0:a="00"+a
        elif k==1:
            a="01"+a
            n-=1
        elif k==2:
            a="10"+a
            n+=2
        elif k==3:
            a="11"+a
            n+=1
        n//=4
    print(int(a))

Submission status: Accepted

Solution code:
#p進数展開と同じ(-2)で割ったあまりを追加していく

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

Submission status: Accepted

Solution code:
from bisect import bisect_left
def inpl(): return list(map(int, input().split()))
N = int(input())

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

searched = [0]*32
while N:
    if N < 0:
        d = bisect_left(L, -N)
        assert searched[d] != 1
        searched[d] = 1
        N += 2**d
    else:
        d = bisect_left(U, N)
        assert searched[d] != 1
        searched[d] = 1
        N -= 2**d
print("0"*(sum(searched) == 0) + "".join(map(str, searched)).rstrip("0")[::-1])

Submission status: Accepted

Solution code:
N = int(input())
 
ans = 0
base = 1
while N != 0:
  p = abs(N%(-2))
  N = (N-p)//(-2)
  ans += p*base
  base *= 10
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = []

def base_mi2(x):
    if x == 1:
        ans.insert(0,'1')
        return ans
    else:
        if x % 2 != 0:
            ans.insert(0,'1')
            return base_mi2(x//(-2)+1)
        else:
            ans.insert(0,'0')
            return base_mi2(x//(-2))

if n == 0:
    print('0')
else:
    print(''.join(base_mi2(n)))

Submission status: Accepted

Solution code:
N = int(input())

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

answer = F(N)
if N == 0:
  answer = '0'
print(answer)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
def solve(n):
    if n==0:
        return '0'
    N=-n
    ans=[]
    while N!=0:
        q,r=divmod(N,-2)
        N=q
        ans.append(-r)
    return ''.join(str(x) for x in (reversed(ans)))

print(solve(int(input())))

Submission status: Accepted

Solution code:
def solve(N):
    if N == 0:
        return "0"
    n = -N
    result = []
    while n != 0:
        q, r = divmod(n, -2)
        #print("%3d %3d %3d" % (n, q, r))
        n = q
        result.append(-r)
    return "".join(str(x) for x in reversed(result))

print(solve(int(input())))
#print(solve(-9)) # 1011
#print(solve(123456789)) # 1011
#print("11000101011001101110100010101")
#print(solve(0)) # 1011

Submission status: Accepted

Solution code:
import math

N = int(input())

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

S = []
while True:
    if N == 1:
        S.append(1)
        break
    tmp = N%2
    S.append(tmp)
    if tmp == 1:
        N -= 1
    N = int(N/(-2))

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

Submission status: Accepted

Solution code:
N = int(input())

def solve(N):
    s = ''
    if N==0:
        s += '0'
    elif N==1:
        s += '1'
    else:
        if N%2==0:
            s += '0'
            s += solve(int(N / (-2)))
        else:
            s += '1'
            s += solve(int((N - 1) / (-2)))
    return s

print(solve(N)[::-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N = int(input())
	
	if N == 0:
		print(0)
		sys.exit()
	
	ans = []
	if N % 2 == 0:
		ans.append("0")
	else:
		ans.append("1")
		N -= 1
		
	i = 1
	#for v in range(5):
	while True:
		tmp = (-2)**i
		i += 1
		
		if (N / tmp) % 2 == 0:
			ans.append("0")
		else:
			ans.append("1")
			N = N - tmp
		
		#print(N)
		if N == 0:
			break
	
	s = ""	
	for i in ans:
		s += i
	print(s[::-1])
		
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
ans=''
while abs(n) > 0:
    ans = str(n % 2) + ans
    n = -(n // 2)
print(ans or 0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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


ans_arr = []

while 1:
    if N == 1:
        ans_arr.append('1')
        break
    if N % 2:
        ans_arr.append('1')
        N -= 1
    else:
        ans_arr.append('0')
    N /= -2
print("".join(reversed(ans_arr)))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())

    rev_answer = ""
    while N != 0:
        rem = N % (-2)
        if rem < 0:
            rem += 2
        N = (N - rem) // (-2)
        rev_answer += str(rem)

    answer = rev_answer[::-1]
    if answer == "":
        answer = 0

    print(answer)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]

    if n==0:
        print(0)
        return

    digit = []
    while n:
        r = abs(n)%2
        digit.append(r)
        n = (n-r)//(-2)

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

solve()

Submission status: Accepted

Solution code:
N = int(input())

i = 0
answer = []
while True:
    if N == 0:
        break
    if N % ((-2)**(i + 1)) != 0:
        answer.append(1)
        N -= (-2)**i
        if N == 0:
            break
    else:
        answer.append(0)
    i += 1

print(''.join(map(str,reversed(answer))) if len(answer) != 0 else '0')

Submission status: Accepted

Solution code:
def nrange(n):
    if n == -1:
        return range(0, 1)
    if n == 0:
        return range(0, 2)

    if n % 2 == 0:
        np = n
        nm = n - 1
    else:
        np = n - 1
        nm = n

    ma = (4**(np // 2 + 1) - 1) // 3
    mi = -2 * (4**((nm + 1) // 2) - 1) // 3

    return range(mi, ma+1)


n = int(input())
k = 0
while n not in nrange(k):
    k += 1

s = ''
while k >= 0:
    if (n in nrange(k)) and (n not in nrange(k-1)):
        n -= (-2)**k
        s += '1'
    else:
        s += '0'

    k -= 1

print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Base -2 Number
https://atcoder.jp/contests/abc105/tasks/abc105_c

"""
import sys


def solve(N):
    if not N:
        return '0'
    r = []
    while N:
        r.append(N % 2)
        N = (N - N % 2) // -2
    return ''.join(map(str, r[::-1]))


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:


#print(-10%3)



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

    i = 0
    ans = '' if n!=0 else '0'
    while n != 0:
        rem = n % ( 2**(i+1) )
#        print((n,i, rem))
  
        ans += '1' if rem>0 else '0'

        n += rem * ( -1 if i%2==0 else 1)
        i += 1
#        if i>10:
#            break
    print(ans[::-1])


main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print(0)
else:
    li = []
    ind = 0
    while N != 0:
        if N % 2**(ind + 1) == 0:
            li.insert(0,0)
            ind += 1
        else:
            li.insert(0,1)
            N -= (-2)**(ind)
            ind += 1            
    x = ''.join([str(li[i]) for i in range(len(li))])
    print(x)

Submission status: Accepted

Solution code:
import math

N = int(input())

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

s = ''
n = N
while n:
    p = math.ceil(n/-2)
    q = n - (p * -2)
    s += str(q)
    n = (n - q)//(-2)

print(s[::-1])

Submission status: Accepted

Solution code:
n = int(input())

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

s = ""
while n != 0:
    s += str(n%2)
    n = (n-n%2)//(-2)

print(s[::-1])

Submission status: Accepted

Solution code:
N = int(input())

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

s = ''
n = N
while n:
    s += str(n % 2)
    n = (n - (n % 2))//(-2)

print(s[::-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
if N == 0:
    print(0)
    sys.exit()
ans = []
tmp = 0

def algo(n):
    if n == 0:
        return 
    
    if n%2 == 0:
        tmp = 0 #tmpは毎回のa0に値する
    else:
        tmp = 1
    ans.append(tmp)
    algo((n-tmp)//(-2))

algo(N)
Str = ''
ans.reverse()
for i in range(len(ans)):
    Str=Str+str(ans[i])
print(Str)

Submission status: Accepted

Solution code:
N = int(input())

def alg(N):
  if N == 0 or N == 1:
    return str(N)
  else:
    return alg(N//2*-1) + str(N%2)
print(alg(N))

Submission status: Accepted

Solution code:
n=int(input())
ans=''
for i in range(40,-1,-1):
  if i==0:
    if n==1:
      ans+='1'
      n=n-1
    else:
      ans+='0'
  elif i==1:
    if -2<=n<=-1:
      ans+='1'
      n=n-(-2)
    else:
      ans+='0'
  elif i%2==1:
    l=-(2*(4**((i+1)//2)-1)//3)
    r=-2**i+(1*(4**((i+1)//2)-1)//3)
    if l<=n<=r:
      ans+='1'
      n=n-((-2)**i)
    else:
      ans+='0'
  else:
    l=2**i-(2*(4**(i//2)-1)//3)
    r=1*(4**(i//2+1)-1)//3
    if l<=n<=r:
      n=n-((-2)**i)
      ans+='1'
    else:
      ans+='0'
if '1' not in ans:
  print(0)
else:
  ans=ans[ans.index('1'):]
  print(ans)

Submission status: Accepted

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


def solve(N: int):
    cur = N
    ret = []
    i = 0
    if N == 0:
        ret = ['0']
    while abs(cur) > 0:
        if i % 2 == 0:
            elm = (2 ** i)
        else:
            elm = -(2 ** i)
        tmp =  2 ** (i + 1)
        #print(cur, elm, tmp)
        if abs(cur - elm) % tmp == 0:
            ret.append('1')
            cur -= elm
        else:
            ret.append('0')
        i += 1
    ret.reverse()
    print(''.join(ret))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(100):
    if N % (2 ** (i+1)) != 0:
        N -= (-2) ** i
        s.append('1')
    else:
        s.append('0')

s.reverse()
t = ''.join(s)
print(int(t))

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    sumnow = 0
    ans = []
    bit = 0
    for i in range(64):
        if (n >> i) & 1 == 0 and bit == 1:
            if i % 2 == 0:
                bit = 0
                sumnow += 1<<i
            else:
                sumnow -= 1<<i
            ans.append('1')
        elif (n >> i) & 1 == 1 and bit == 0:
            if i % 2 == 0:
                sumnow += 1<<i
            if i % 2 == 1:
                bit = 1
                sumnow -= 1<<i
            ans.append('1')
        else:
            ans.append('0')

        if sumnow == n:
            for a in reversed(ans):
                stdout.write(a)
            print()
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
n=int(input())
def f(i,x):
    if i%2==0:
        if (2**i+2)//3<=x<=(2**(i+2)-1)//3:
            return True
        else:
            return False
    else:
        if -(2**(i+1)-1)*2//3<=x<=-(2**i+1)//3:
            return True
        else:
            return False
if n==0:
    print('0')
else:
    ans=''
    order=0
    mark=f(order,n)
    while not mark:
        order=order+1
        mark=f(order,n)
    while order>=0:
        if f(order,n):
            ans=ans+'1'
            n=n-(-2)**order
        else:
            ans=ans+'0'
        order=order-1
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

i = 1
num = ""
SUM = 0
amari = 1
if n == 0:
  num = "0"
while not(n == amari == SUM or SUM == n): #or num == "":
  amari = n % 2**i
  if amari == SUM % 2**i:
    num += "0"
  else:
    SUM += (-2)**(i-1)
    num += "1"
  i += 1
  #print(amari,SUM)
print(num[::-1])

Submission status: Accepted

Solution code:
n = int(input())

i = 1
num = ""
SUM = 0
amari = 1
while not(n == amari == SUM or SUM == n) or num == "":
  amari = n % 2**i
  if amari == SUM % 2**i:
    num += "0"
  else:
    SUM += (-2)**(i-1)
    num += "1"
  i += 1
  #print(amari,SUM)
print(num[::-1])

Submission status: Accepted

Solution code:
N = int(input())

S = str()
a = True
count = 1
memo = 0
while a:
    amari = N%(2 ** count)
#    print ('amari', amari)
    if (amari- memo) == 2 ** (count-1):
        s = 1
    else:
        s = 0
    memo = memo + s * (-2) **(count-1)
#    print ('momo', memo)
    S = str(s) + S
    count += 1
    if memo == N:
        print (S)
        a = not a

Submission status: Accepted

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

Submission status: Accepted

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

while n != 0:
    now = n % -2
    n //= -2
    if now == -1:
        n += 1
        now *= -1
    s.append(str(now))
print(''.join(s[::-1]))

Submission status: Accepted

Solution code:
n = int(input())
tmp = 0
digit = 2
exponent = 1
baseMinor2 = ''

while(tmp!=n):
  #2^nで割った余りを合わせる
  if(n % digit) == (tmp % digit):
    baseMinor2 = '0' + baseMinor2
  else:
    baseMinor2 = '1' + baseMinor2 
    tmp += exponent
    
  exponent *= -2
  digit *= 2
if baseMinor2 == '':
  print(0)
else:
  print(baseMinor2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ans=str(n%2)
n//=2
while n:
    ans+=str(n%2)
    n//=-2
print(ans[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
if a==-1:
    print("11")
    exit()
if a==0:print("0")
b=""
c=2
d=0
n=0
if a > 0:
    m=a
else:
    m=-a-1
while m >d:
    if (a-d-1)%c < c//2:
        b+="1"
    else :
        b+="0"
    c*=2
    n=1-n
    d=d+(3*d+1)*n
if a < 0:
    if b[-1]=="0":b=b[:-1]
    if (a-d-1)%c < c//2:
        b+="1"
    

print(b[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
if n==0:
    print(0)
    exit()
ans = ""
p = False
while n:
    n, m = divmod(n, 2)
    ans = str(m) + ans
    if p & m:
        n += 1
    p = not p
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

li1 = [0]* 20
li2 = [0]* 20
count = 1

for i in range(19):
    li1[i+1] = li1[i] + 4 ** i
    li2[i+1] = li2[i] - 2 * 4 ** i

if n == 0:
    s = [0]
elif n > 0:
    for i in range(20):
        if li1[i] < n and li1[i+1] >= n:
            a = i
            s = [0] * (2*i+1)
            s[0] = 1
            n -= (-2) ** (2*i)
            #print(n)
            break
    while a > 0:
        a -= 1
        if li2[a] > n and li2[a+1] <= n:
            s[count] = 1
            n -= (-2) ** (2*a+1)
            count += 1
            #print(n)
        else:
            s[count] = 0
            count += 1
            #print(n)
        if li1[a] < n and li1[a+1] >= n:
            s[count] = 1
            n -= (-2) ** (2*a)
            count += 1
            #print(n)
        else:
            s[count] = 0
            count += 1
            #print(n)
    #print(s)
else:
    for i in range(20):
        if li2[i] > n and li2[i+1] <= n:
            a = i
            s = [0] * (2*(i+1))
            s[0] = 1
            n -= (-2) ** (2*i+1)
            #print(n)
            break
    if li1[a] < n and li1[a+1] >= n:
        s[count] = 1
        n -= (-2) ** (2*a)
        count += 1
        #print(n)
    else:
        s[count] = 0
        count += 1
        #print(n)
    while a > 0:
        a -= 1
        if li2[a] > n and li2[a+1] <= n:
            s[count] = 1
            n -= (-2) ** (2*a+1)
            count += 1
            #print(n)
        else:
            s[count] = 0
            count += 1
            #print(n)
        #print(li[a],li[a+1])
        if li1[a] < n and li1[a+1] >= n:
            s[count] = 1
            n -= (-2) ** (2*a)
            count += 1
            #print(n)
        else:
            s[count] = 0
            count += 1
            #print(n)
    #print(s)

ans = ''

for i in range(len(s)):
    ans = ans + str(s[i])

print(ans)

Submission status: Accepted

Solution code:
def to_m2(n):
    if n == 0:
        return "0"

    digits = []
    i = 0
    base = 1
    while n != 0:
        if n % (base * 2) == 0:
            digits.append("0")
        else:
            digits.append("1")
            n -= base
        i += 1
        base *= -2
    digits.reverse()
    return "".join(digits)


N = int(input())
print(to_m2(N))

Submission status: Accepted

Solution code:
n = int(input())
b = [int(bk) for bk in format(abs(n), "b")[::-1]] + [0] * 3
if n>=0:
    for i, bk in enumerate(b):
        if i % 2 and bk:
            b[i + 1] += 1
else:
    for i, bk in enumerate(b):
        if i % 2==0 and bk:
            b[i + 1] += 1
for i, bk in enumerate(b):
    if bk > 1:
        if b[i + 1] > 0:
            b[i + 1] -= 1
        else:
            b[i + 1] += 1
            b[i + 2] += 1
        b[i] -= 2
print(int("".join(map(str,b[::-1]))))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
L = [ ]
import math
while True:
    tmp = math.ceil(N / (-2))
    L.append(N - tmp *(-2))
    N = tmp
    if tmp == 0:
        break
L = L[::-1]
for x in L:
    print(x,end="")

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
"""解説
？進数の計算

 1  0  1 1
-8  4 -2 1
----------
-8 + -2 + 1 = -9

                    1   -2    4    -8      16
1のとき表現できる数  1~1 -2~1  2~5 -10~-3   6~21
0のとき表現できる数  0~1  0~1 -2~1  -2~5  -10~5
                   ----------------------------
                   0~1  -2~1 -2~5 -10~5  -10~21      


(1) -9のときを考える
-9は2で割り切れないので、0bit目は必ず1になる。(※1)

-9を-2進数で表現すると、 

?????1

になるはず。

ということは?????0は-10である。

?????の部分はいくつか？と考えたとき、
一桁減らすので、-2で割るとよい。（-2進数なので。10進数のときは10で割るでしょ？）

よって、?????の部分は5

(2) 5のときを考える
5は2で割り切れないので、0bit目は必ず1になる(※2)

5を-2進数で表現すると、

????1

になる。

ということは????0は4である。

????の部分はいくつか？と考えたとき、
一桁減らすので、-2で割る。

よって、????の部分は-2

(3) -2のときを考える
-2は2で割り切れるので、0bit目は0である。(※3)

-2を-2進数で表現すると、

???0

???の部分はいくつか？と考えたとき、
一桁減らすので、-2で割る。

よって、???の部分は1

(4) 1のときを考える
1は2で割り切れないので、0bit目は1(※4)

1を-2進数で表現すると、

??1

??0は0

??の部分はいくつか？と考えたとき、当然0でしょう。

よって、答えは、
(※4)(※3)(※2)(※1)で、
1011
になる。

この一連の計算を一般化すればよい。

"""
def solve():
    N = int(input())
    ans = ""
    
    if N==0:
        print(N)
        return

    while N!=0:
        if N%2 != 0:
            # 2で割り切れない
            ans = "1" + ans
            N -= 1
            N //= -2
        else:
            ans = "0" + ans
            N //= -2
    
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def c():
   
    K = int(input())
    ans = ""
    if K == 0:
        print(0)
        return 0
    while True:
        amari = -1*(K%-2) 
        # print(amari,end = "")
        ans += str(amari)
        K = (K-amari) / (-2)
        K = int(K)
        # print("K=",K)
        if K == 0 or K == 1:
            break
    ans += str(K)
    print(ans[::-1])
if __name__ == '__main__':
    c()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N = int(input())

s = []
b = 2
if N == 0:
    print(0)
    exit()
while N != 0:
    if N % b == 0:
        s.append(str(0))
    else:
        s.append(str(1))
        N -= int(b/2)
    b *= -2

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

Submission status: Accepted

Solution code:
n = int(input())
bit = []
base = 2
if n==0:
    print(0)
    exit()
while n != 0:
    # print(n)
    if n % (base) == 0:
        bit.insert(0,0)
    else:
        bit.insert(0, 1)
        n -= int(base/2)
    base *= -2
bit = map(str,bit)
print("".join(bit))