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())
lis = [0]*40
tmp = [2]+[2**(i*2) for i in range(1,23)]
rui = [0]
for t in tmp:
    rui.append(rui[-1]+t)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))

Submission status: Accepted

Solution code:
from numpy import cumsum
N = int(input())
lis = [0]*40
tmp = [0,2]+[2**(i*2) for i in range(1,23)]
rui = cumsum(tmp)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))

Submission status: Accepted

Solution code:
n = int(input())

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

minus = False
if n < 0:
    minus = True
    n *= -1

a = [int(x) for x in format(n, "050b")[::-1]] 
m = len(a)

for i in range(m):
    if a[i] and ((i % 2 and not minus) or (not i % 2 and minus)):
        a[i+1] += 1

for i in range(m):
    if a[i] == 2:
        a[i] = 0
        if a[i+1] >= 1:
            a[i+1] -= 1
        else:
            a[i+1] += 1
            a[i+2] += 1

ans = []
flg = False
for x in a[::-1]:
    if x == 1: flg = True
    if flg: ans.append(str(x))

print("".join(ans))

Submission status: Accepted

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

Submission status: Accepted

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

ans = list()
while n != 0:
    ans.append(str((n%-2)*(-1)))
    if n % (-2) < 0:
        n = (n-1) // (-2)
    else:
        n = n // (-2)

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

Submission status: Accepted

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

ans = list()
while n != 0:
    ans.append(str((n%-2)*(-1)))
    if n % (-2) < 0:
        n = n // (-2) + 1
    else:
        n = n // (-2)

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	n = INT()
	if n == 0:
		print(0)
		sys.exit()
		
	ans = []
	while n != 0:
		ans.append((n % (-2))*(-1))
		if n%(-2) < 0:
			n = n//(-2) + 1
		else:
			n = n//(-2)

	print(*ans[::-1], sep = '')


if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

s = []
tmp = N
if N == 0:
	print(0)
	sys.exit()
while tmp != 1:
	s.append(str(-1*(tmp%(-2))))
	tmp = ceil(tmp/(-2))
s.append("1")
print("".join(s)[::-1])

Submission status: Accepted

Solution code:
N = int(input())
MOD=[]

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

for i in range(1,10**9):
    if 2**(i-3)>abs(N):
        break
    MOD.append(N%(2**i))
#print(MOD)
ans = []
def value(ans):
    buff=0
    for i,a in enumerate(ans):
        buff += a*((-2)**i)
    return buff

for i,mod in enumerate(MOD):
    divide = 2**(i+1)
    if value(ans) % divide == mod:
        ans.append(0)
    else:
        ans.append(1)
#print(ans,value(ans))
ans = list(reversed([str(i) for i in ans]))
while ans[0]=="0":
    ans.pop(0)
print("".join(ans))

Submission status: Accepted

Solution code:
N = int(input())

ans = ""

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

N = int(input().strip())
ans = deque([])
if N == 0:
  print(0)
  exit()
while N != 0:
    if N % -2 != 0:
        N -= 1
        ans.appendleft('1')
    else:
        ans.appendleft('0')
    N /= -2

print(''.join(ans))

Submission status: Accepted

Solution code:
N = int(input())

def get_ans(x):
    if x == 0:
        return ['0']
    d = []
    i = 0
    div = 1
    while x != 0:
        if x % (div*2) == 0:
            d.append('0')
        else:
            d.append('1')
            x -= div
        i += 1
        div = div * (-2)
    return d

a = get_ans(N)
b = list(reversed(a))
ans = ''.join(b)
print(ans)

Submission status: Accepted

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

ansl = []
if n == 0:
    print("0")
    sys.exit()
while n:
    if n % -2 == 0:
        ansl.append("0")
    else:
        n -= 1
        ansl.append("1")
    n = n // -2

ansl.reverse()
print("".join(ansl))

Submission status: Accepted

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

if n%2 == 0:
	s.append(0)
else:
	s.append(1)
i = 1
nn = n - s[i-1]
while nn != 0:
	if nn%(2**(i+1)) == 0:
		s.append(0)
	else:
		s.append(1)
	nn -= s[i]*(-2)**i
	i += 1
s.reverse()
print("".join(map(str, s)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

num = -n
ans = ""
#num = -n

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

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

Submission status: Accepted

Solution code:
n = int(input())

num = -n
ans = []
#num = -n

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

while num!= 0:
    if num == 1:
        ans.append(11)
        break
    if num == -1:
        ans.append(1)
        break
    if num % (-2) == 0:
       ans.append(0)
    else:
        ans.append(1)
    num //= (-2)
    #print(num)
    
print(*ans[::-1],sep='')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

sign = 1
S = []
while N!=0:
    S.append(N%2)
    N = (N - S[-1]*sign)//2
    sign *= -1

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n=int(input())
	ans=[]
	
	if n==0:
		print(0)
		exit(0)
	
	while True:
		if -1<n<1:
			break
		elif n%(-2)==-1:
			ans.append(1)
			n=n//(-2)+1
		elif n%(-2)==1:
			ans.append(1)
			n=n//(-2)
		else:
			ans.append(0)
			n //= (-2)
	ans=ans[::-1]
	ans="".join(map(str,ans))
	
	print(ans)
	
	

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

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

high=[2**(2*i)  for i in range(16)]
low=[-2**(2*i+1) for i in range(16)]
hh=[]
ll=[]
sum_h=0
sum_l=0
for i in range(16):
    sum_h+=high[i]
    sum_l+=low[i]
    hh.append(sum_h)
    ll.append(sum_l)

    
flag=True
while N!=0:
    #print(N)
    if N>0:
        for index,item in enumerate(hh):
            if N-item<=0:
                if flag:
                    l=[0]*(2*index+1)
                    flag=False
                l[-2*index-1]=1
                N-=high[index]
                break
    else:
        for index,item in enumerate(ll):
            if N-item>=0:
                if flag:
                    l=[0]*(2*index+2)
                    flag=False
                    length=len(l)
                l[-2*index-2]=1
                N-=low[index]
                break

print("".join(list(map(str,l))))
"""
print(high)
print(low)
print(hh)
print(ll)
"""

Submission status: Accepted

Solution code:
N = int(input())

L = [[0,1]]
i = 1
while True:
	d = (-2) ** i
	if d < 0:
		L.append([L[-1][0]+d,L[-1][1]])
	else:
		L.append([L[-1][0],L[-1][1]+d])

	a,b = L[-1]
	if a <= N <= b:
		break

	i += 1
		
ans = []
tmp = N
for i in reversed(range(len(L))):
	if i == 0:
		if tmp == 1:
			ans.append("1")
		else:
			ans.append("0")
		break

	add = (-2) ** i
	a,b = L[i]
	c,d = L[i-1]
	if a == c:
		if d < tmp <= b:
			ans.append("1")
			tmp -= add
			continue
	elif b == d:
		if a <= tmp < c:
			ans.append("1")
			tmp -= add
			continue

	ans.append("0")

if ans[0] == "0":
	ans.pop(0)

print("".join(ans))

Submission status: Accepted

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

if N == 0:
    print(0)

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

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

Submission status: Accepted

Solution code:
n = int(input())


def F2(n):
    if n // 2 == 0:
        return str(n % 2)
    return F2(-(n // 2)) + str(n % 2)


print(F2(n))

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n == 0:
        print(0)
    else:
        ans = []
        while n:
            if n % -2 == 0:
                ans.append("0")
                n //= -2
            else:
                ans.append("1")
                n //= -2
                n += 1
        ans.reverse()
        print("".join(ans))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = int(input())

num = ''
def division(N):
  if N%2==0:
    return N//-2,'0'
  else:
    return (N//-2)+1,'1'
  
  
if S==0:
  print(0)
else:
  while S!=0:
    a,b = division(S)
    num += b
    S = a
  print(num[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-09 11:51:37(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 


def baseConvert(n, base):
    if n == 0:
        return ''
    else:
        for i in range(abs(base)):
            if n % abs(base) == i:
                return baseConvert((n - i) // base, base) + str(i)
 
def main():
    n = int(sys.stdin.readline().rstrip())
    base = -2
    
    if n == 0:
        ans = '0'
    else:
        ans = baseConvert(n, base)
    print(ans)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
-9
#                         author:  kagemeka 
#                         created: 2019-11-09 11:51:37(JST)
### modules
## from standard library
import sys
# import collections
import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 


def f(n):
    if n == 0:
        return ''
    else:
        if n % 2 == 0:
            return f(n // (-2)) + '0'
        else:
            return f((n - 1) // (-2)) + '1'
    
 
def main():
    n = int(sys.stdin.readline().rstrip())
    
    if n == 0:
        ans = '0'
    else:
        ans = f(n)
    print(ans)
    





if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

pl = [int(((4**i) - 1)/3) for i in range(1,20)]
mi = [int(-2 * ((4**i) - 1)/3) for i in range(20,0,-1)]
plli = [int(4 ** i) for i in range(20)]
mili = [int(-2 * (4**i)) for i in range(19,-1,-1)]
li = []

import bisect

def func(n):
    if n == 0:
        return None
    elif n > 0:
        inde = bisect.bisect_left(pl,n)
        li.append(2*inde + 1)
        m = n-plli[inde]
        func(m)
    else:
        inde = bisect.bisect_right(mi,n)
        li.append((20 - inde + 1) * 2 )
        m = n-mili[inde-1]
        func(m)

if n == 0:
    print(0)
else:
    func(n)
    lis2 = []
    for i in range(li[0]):
        lis2.append("0")
    for a in li:
        lis2[-a] = "1"
    st = "".join(lis2)
    print(st)

Submission status: Accepted

Solution code:
def conv(s):
    s = list(s)
    s.reverse()
    ret = 0
    for i in range(len(s)):
        ret += int(s[i]) * (-2)**i
    return ret

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

s = ''
d = 2
while abs(n) > 0:
    if n % d == 0:
        s = '0' + s
    else:
        s = '1' + s
    n -= conv(s[0]+'0'*(len(s)-1))
    d *= 2

print(s)

Submission status: Accepted

Solution code:
Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

ttl = n
ans = []

memo = -2
memo2 = 1

while(abs(ttl)>0):
    if ttl%memo != 0:
        ttl -= memo2
        ans.append(1)
    else:
        ans.append(0)

    memo *= (-2)
    memo2 *= (-2)

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

Submission status: Accepted

Solution code:
n=int(input())

l=list()
c=0
if n==0:
  l.append(0)
while n!=0:
  if n%2:
    l.append(1)
    n -= -1 if c%2 else 1
  else:
    l.append(0)
  n //= 2
  c += 1

for i in reversed(l):
  print(i, end='')

print()

Submission status: Accepted

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

Submission status: Accepted

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

rest = N
i = 0
ans_l = []

while not rest == 0:
    if rest % (-2)**(i+1) == 0:
        ans_l.append('0')
    else:
        ans_l.append('1')
        rest -= (-2)**i
    i += 1

# print('----------output----------')
ans = ''.join(ans_l[::-1])
if N == 0:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)
    exit()
else:
    ans = ""
    while N != 0:
        if N % 2 == 1:
            ans = "1" + ans
            if N > 0:
                N = (N // 2) * (-1)
            else:
                N = N // (-2) + 1
        else:
            ans = "0" + ans
            N = N // (-2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
answer = F(N)
if N == 0:
    answer = 0
print(answer)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
res = [N % 2]
for i in range(1, N.bit_length() * 2):
  t = N % pow(2, i + 1)
  u = 0
  for j in range(i):
    u += res[j] * pow(-2, j)
  if u % pow(2, i + 1) == t:
    res.append(0)
  else:
    res.append(1)
res.reverse()
rres = ""
f = 1
for i in range(len(res)):
  if f and res[i] == 0:
    continue
  if f and res[i]:
    f = 0
  rres += str(res[i])
if rres == "": print(0)
else: print(rres)

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
    print(0)
    exit()
ans=str("")
while(n!=0):
    r=n%2
    if r<0:
        r+=2
    n=(n-r)//(-2)
    ans=str(r)+ans
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 /= -2

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

Submission status: Accepted

Solution code:
# ABC105 C - Base -2 Number
# 2019/10/28

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

    a = []
    while n!= 0:
        r = n % 2
#         print('r={0}, n={1}'.format(r,n))
        
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        
    if a == []:
        a.append(0)
        
    a.reverse()
#     print(a)
    
    print("".join(map(str,a)))


if __name__ == "__main__":
    main()

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"

if n==0:
    print(0)
else:
    print(f(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
    if a == []:
        a.append(0)
    a.reverse()
    return "".join(map(str,a))
print(basen(n))

Submission status: Accepted

Solution code:
import sys
n=int(input())
if n==0:
    print(0)
    sys.exit()
ans=""
for i in range(2**31):
    a=(-2)**i
    if (n//a)%2==1:
        ans="1"+ans
        n-=a
        if n==0:
            print(ans)
            break
    else:
        ans="0"+ans

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
res = ""
cnt = 0
div = 0
if n == 0:
    print(0)
else:
    while n != 0:
        div = n % 2**(cnt+1)
        div = 1 if div > 0 else 0
        res = str(div) + res
        if div > 0:
            n -= (-2) ** cnt
        cnt += 1
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
for i in range(10**5):
  if n % 2 ** (i + 1) != 0:
    n -= (-2) ** i
    ans = "1" + ans
  else:
    ans = "0" + ans
  if n == 0:
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input().strip())

ans = []

while abs(N) > 0:
    ans.append(abs(N) % 2)
    N = (N // 2) * -1

if not len(ans):
    ans = [0]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=''

while N!=0:
    A=str(N%2)+A
    N=-(N//2)

print(A if A!='' else '0')

Submission status: Accepted

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

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

print(0 if x == '' else x)

Submission status: Accepted

Solution code:
n = int(input())

s = []
while n != 0:
    r = n % 2
    s.append(r)
    n -= r
    n //= -2

if s:
    print(''.join(map(str, reversed(s))))
else:
    print(0)

Submission status: Accepted

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

while n != 0:
    if n%2 == 0:
        
        s = "0" + s
    elif n%2 == 1:
        n -= 1
        s = "1" +s
    n = (n//-2)

print(s)

Submission status: Accepted

Solution code:
n = int(input())
dp = [2**i if i % 2 == 0 else -2**i for i in range(32) ]

if n < 0 :
    plus_minus = 1
elif n > 0:
    plus_minus = 0
else:
    print(0)
    exit()

a = 0
for i in range(plus_minus,32,2):
    if abs(dp[i]) + abs(a) > abs(n):break
    a += dp[i]
s = "1"

if plus_minus == 1:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 0:
            if (b + dp[j]) + a <= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            a -= dp[j]
            if b + a > n:
                s += "1"
                b += dp[j]
            else:
                s += "0"

else:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 1:
            if (b + dp[j]) + a >= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            a -= dp[j]
            if b + a < n:
                s += "1"
                b += dp[j]
            else:
                s += "0"
print(s)

Submission status: Accepted

Solution code:
import math
import sys

n = int(input())
if n == 0:
  print(0)
  sys.exit()
  
keta = 0
under = 0
s = ""
nn = 1

if n > 0:
    while True:
      if sum([2**i for i in range(0,nn,2)])+1<= n and n <= sum([2**i for i in range(0,nn+1,2)]):
          keta = nn+1
          under = sum([2**i for i in range(0,nn,2)])
          break
      else:
          nn+=1

    for i in range(1,keta):
        remainder = (n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "0" if i%2==1 else "1"
        else:
            s += "1" if i%2==1 else "0"
    else:
        s+="1"
    print(s[::-1])

else:
    while True:
        if n <= sum([(-2)**i for i in range(1,nn,2)]) and n >= sum([(-2)**i for i in range(1,nn+1,2)]):
            keta = nn+1
            under = sum([(-2)**i for i in range(1,nn,2)])
            break
        else:
            nn+=1

    for i in range(1,keta):
        remainder = abs(n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "1" if i%2==1 else "0"
        else:
            s += "0" if i%2==1 else "1"
    else:
        s+="1"
    print(s[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lmax = [0]
lmin = [0]
tmin = 0
tmax = 0
for i in range(0,40):
    if i % 2 == 1:
        tmin -= 2**i
    else:
        tmax += 2**i
    lmax.append(tmax)
    lmin.append(tmin)

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

    print(int(base(n,35)))

def base(n,a):
    if a == 0:
        if n == 1:
            return '1'
        else:
            return "0"
    if n >lmax[a] or n <lmin[a]:
        return '1'+base(n-(-2)**a,a-1)
    else:
        return '0'+base(n,a-1)

main()

Submission status: Accepted

Solution code:
N = int(input())
res = []
while N != 0:
    if N % -2 != 0:
        res.append("1")
    else:
        res.append("0")
    
    if N == 1:
        break

    if N % -2 != 0:
        N -= 1
    N //= -2

if N != 0:
    print("".join(reversed(res)))
else:
    print(0)

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

# n, k = map(int, input().split())
n = getInputInt()

ans = 0

flg = True
i=0
while(flg):
    tmp = pow(-2,i+1)
    if n % tmp != 0:
        ans+=pow(10,i)
        n -= pow(-2,i)

    if n==0:
        flg=False
    i+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []
x = N

while x != 1:
    if x % 2 == 0:
        ans.append('0')
    else:
        ans.append('1')
        x -= 1
    x /= -2
ans.append('1')

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = []
x = N

while x != 1:
    if x % 2 == 0:
        ans.append('0')
    else:
        ans.append('1')
        x -= 1
    x /= -2
ans.append('1')

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

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
    print(0)
else:
    m, ans = n, ''
    while m:
        m, r = divmod(m, 2)
        m, ans = -m, '{}{}'.format(r, ans) 
    print(ans)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
if n == 0:
    print(0)
else:
    def f(x):
        q, r = divmod(x, -2)
        return (q+1, 1) if r == -1 else (q, r)

    m = n
    ans = ''
    while m:
        m, r = f(m)
        ans = str(r) + ans
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

if n == 0:
    print(0)
else:
    p = 1
    ans_list = []
    while n != 0:
        ans_list.append(str(n%2))
        n = - (n//2)
    ans_list.reverse()
    print("".join(ans_list))

Submission status: Accepted

Solution code:
N=int(input())
s=''
for i in range(1,35):
    if N%(2**i)==0:
        s='0'+s
    else:
        s='1'+s
    N-=N%-((-2)**i)
    if N==0:
        break
print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
import math

N = int(input())

# d桁の-2進法表記で表現できる最大の数を返す関数。偶数桁目のbitが全て1、奇数桁目のbitが全て0
def max_negative2(d):
    if d == 1:
        return 1
    elif d%2 == 1:
        return int((1-4**(math.ceil(d/2)))/(1-4))
    else:
        return (-2)**(d-1) + int((1-4**(math.ceil(d/2)))/(1-4))

def min_negative2(d):
    if d == 1:
        return 0
    elif d%2 == 1:
        return (-2)**(d-1) + int((-2)*(1-4**(d//2))/(1-4))
    else:
        return int((-2)*(1-4**(d//2))/(1-4))

# 10進数の数値nと桁数dを与えると、nを-2進法表記したときにd桁目が1となるかどうかを返す関数
def top_bit_flag(n,d):
    if n == 0 and d == 1:
        return False
    else:
        return True if min_negative2(d) <= n <= max_negative2(d) else False

# Nの-2進数表記を大きい桁から埋めていく
# -10**9<=N<=10**, min_negative2(31)<10**9<max_negative2(31), min_negative2(32)<-10**9<max_negative2(32)なので、Nは-2進法表記時に最大で32桁
S = ""
n = N
for d in reversed(range(1,33)):
    if top_bit_flag(n,d):
        S += "1"
        n -= (-2)**(d-1)
    else:
        S += "0"

print(int(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)

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

print(ans[::-1])

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

n=I()
ans=0
d=0

while n!=0:
    k=2**(d+1)
    if n%k!=0:
        ans+=1*10**d
        n-=(-2)**d
    d+=1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = ''
while(N != 0):
  r = N % 2
  ans += str(r)
  N = (N-r) // (-2)
  #print(N,r)
print(''.join(reversed(ans)))