Problem:


４進数

10 進数は現在使われている一般的な記数法で、0、1、2、3、4、5、6、7、8、9 の10 個の記号を用いて全ての数字を表します。

2 進数はコンピュータの世界でよく使われる記数法で、0 と1 の二つの記号を用いて全ての数字を表します。

4 進数で用いられるのは 0、1、2、3 の 4 つの数字だけです。4 進数では 0 から順に数を増やしていったときに 4 まで来たら次の位に桁上がりします。そのため、10 進数の 4 は桁上がりして「10」という表現になります。

10 進数
0
1
2
3
4
5
6
7
8
9
10
...

2 進数
0
1
10
11
100
101
110
111
1000
101
1010
...

4 進数
0
1
2
3
10
11
12
13
20
21
22
...

昔ハワイでは魚やタロイモを指にはさんで数えていたので、10 進数ではなく4 進数を使っていたそうです。

10 進数で入力される整数 n を 4 進数に変換し出力するプログラムを作成してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりは -1 ひとつの行で示されます。各データセットとして１つの整数 n (0 ≤ n ≤ 1000000) が１行に与えられます。

データセットの数は 2000 を超えません。

Output

入力データセット毎に 4 進数に変換した結果を１行に出力します。

Sample Input

7
4
0
12
10
10000
-1

Output for the Sample Input

13
10
0
30
22
2130100



Sample input:
7
4
0
12
10
10000
-1


Sample output:
13
10
0
30
22
2130100

Submission status: Wrong Answer

Solution code:
while 1:
  a = input()
  if a<0: break
  x=''
  while a:
    x = str(a % 4)+x
    a/=4
  print [x[::-1],'0'][x=='']

Submission status: Wrong Answer

Solution code:
import sys
def main():
    ds = []
    for line in sys.stdin:
        n = int(line)
        if n != -1:
            ds.append(n) #data set
        elif n == -1:
            for i in range(len(ds)):
                if ds[i] != 0:
                    hoge = []
                    p = ds[i]
                    while True:
                        foo = p // 4
                        bar = p % 4
                        if foo >= 4:
                            hoge.append(bar)
                            p = foo
                        elif foo < 4:
                            hoge.append(bar)
                            hoge.append(foo)
                            break
                    hoge.reverse()
                    hoge = [str(hoge[i]) for i in range(len(hoge))]
                    fuga = ""
                    for j in range(len(hoge)):
                        fuga += hoge[j]
                    print(fuga)
                elif ds[i] == 0:
                    print(0)
            else:
                    break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == -1:
            break
        else:
            if n != 0:
                hoge = []
                while True:
                    foo = n // 4
                    bar = n % 4
                    if foo >= 4:
                        hoge.append(bar)
                        n = foo
                    elif foo < 4:
                        hoge.append(bar)
                        hoge.append(foo)
                        break
                hoge.reverse()
                hoge = [str(hoge[i]) for i in range(len(hoge))]
                fuga = ""
                for i in range(len(hoge)):
                    fuga += hoge[i]
                print(fuga)
            elif n == 0:
                print(n)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
while True:
    n=input()
    if n==0:break
    s=""
    while n>0:
        s=str(n%4)+s
        n/=4
    print s

Submission status: Accepted

Solution code:
while 1:
  a = input()
  if a<0: break
  x=[]
  while a:
    x.append(str(a % 4))
    a/=4
  if x==[]: x="0"
  print "".join(x[::-1])

Submission status: Accepted

Solution code:
while 1:
  a = input()
  if a<0: break
  x=''
  while a:
    x = str(a % 4)+x
    a/=4
  print [x,'0'][x=='']

Submission status: Accepted

Solution code:
while True:
	n = input()
	if n == -1 : break

	four = []
	while n > 0:
		four.append(str(n % 4))
		n /= 4
		
	if len(four) == 0:
		print 0
	else:
		four.reverse()
		print "".join(four)

Submission status: Accepted

Solution code:
while 1:
    a=int(input())
    if a<0:break
    ans='' if a!=0 else '0'
    while a:ans,a=str(a%4)+ans,a//4
    print(ans)

Submission status: Accepted

Solution code:
while True:
    v = int(input())
    if v == -1:
        break
    if v < 4:
        print(v)
    else:
        b = str(bin(v))[2:]
        bb = [b[i:i+2] for i in range(len(b)-2, -1, -2)]
        if len(b) % 2 != 0:
            bb.append(b[0])
        ans = []
        for t in bb:
            tmp = 0
            for i, v in enumerate(t[::-1]):
                tmp += pow(2, i) * int(v)
            ans.append(tmp)
        print(''.join(map(str, ans[::-1])))

Submission status: Accepted

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == -1:
            break
        else:
            if n != 0:
                hoge = []
                while True:
                    foo = n // 4
                    bar = n % 4
                    if foo >= 4:
                        hoge.append(bar)
                        n = foo
                    elif foo < 4:
                        hoge.append(bar)
                        hoge.append(foo)
                        break
                hoge.reverse()
                hoge = [str(hoge[i]) for i in range(len(hoge))]
                fuga = ""
                for i in range(len(hoge)):
                    fuga += hoge[i]
                print(int(fuga))
            elif n == 0:
                print(n)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Aizu Problem 00175: Quaternary Notation
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

VALUES = {chr(65+i): 10+i for i in range(26)}
for i in range(10):
    VALUES[str(i)] = i
INV_VALUES = {value: key for key, value in VALUES.items()}

POWERS = {(base, power): base**power for base in range(1, 37) for power in range(200)}

def from_base(k, base_k):
    # convert integer k in base base_k to decimal (base 10)
    L = len(k)
    res = 0
    for i in range(L - 1, -1, -1):
        res += VALUES[k[i]] * POWERS[(base_k, L - 1 - i)]
    return res

def to_base(d, to_base):
    if d == 0:
        return 0
    # convert decimal integer (base 10) to base base_k
    res = ""
    for p in range(50, -1, -1):
        power = POWERS[(to_base, p)]
        m = d // power
        res += INV_VALUES[m]
        d = d % power
    while res[0] == '0':
        res = res[1:]
    return res


while True:
    n = int(input())
    if n == -1:
        break
    print(to_base(n, 4))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0175

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        n = int(input())
        if n == -1:
            break

        q = []
        q.append(n % 4)
        while n > 3:
            n //= 4
            q.append(n % 4)

        q.reverse()
        print(''.join(map(str, q)))


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

Submission status: Accepted

Solution code:
BASE = 4

while True:

    input_num = int(input())

    if input_num == -1:
        break

    result = ""

    while True:
        quotient, remainder = divmod(input_num, BASE)

        result = str(remainder) + result

        if input_num < BASE:
            break

        input_num = quotient

    print(result)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == -1:
        break
    if n == 0:
        print(0)
    else:
        ans = []

        while n > 0:
            ans.append(n % 4)
            n = n // 4

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

Submission status: Accepted

Solution code:
# AOJ 0175 Quaternary Notation
# Python3 2018.6.19 bal4u

while True:
	n = int(input())
	if n < 0: break
	if n == 0: print(0)
	else:
		ans = []
		while n > 0:
			ans.append(str(n & 3))
			n >>= 2
		print(*ans[::-1], sep='')

Submission status: Accepted

Solution code:
def to_four(n):
  if n == 0:
    return "0"
  acc = ""
  while n:
    acc = str(n % 4) + acc
    n //= 4
  return acc

while True:
  n = int(input())
  if n == -1:
    break
  print(to_four(n))

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==-1:break
    s=""
    while n>0:
        s=str(n%4)+s
        n/=4
    if s=="":print 0
    else:    print s

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n==-1: break
    if n==0:
        print 0
    else:
        s = ""
        while n>0:
            s=str(n%4)+s
            n/=4
        print s

Submission status: Accepted

Solution code:
from operator import add,getitem
b2q = {"00":"0","01":"1","10":"2","11":"3"}
while True:
    n = input()
    if n == -1:
        break
    s = format(n,"b")
    if len(s) % 2 == 1:
        s = "0" + s
    print "".join(map(b2q.get,map(add,s[::2],s[1::2])))

Submission status: Accepted

Solution code:
from operator import add
b2q = {"00":"0","01":"1","10":"2","11":"3"}
while True:
    n = input()
    if n == -1:
        break
    s = format(n,"b")
    if len(s) % 2 == 1:
        s = "0" + s
    print "".join(map(b2q.get,map(add,s[::2],s[1::2])))

Submission status: Accepted

Solution code:
def f(n):
	a = ""
	while n>0:
		a += str(n%4)
		n //= 4
	return a[::-1]
	
while 1:
	n = input()
	if n == -1: break
	print f(n) if n > 0 else 0

Submission status: Accepted

Solution code:
import math
while 1:
    n = int(input())
    if n == -1:
        break
    elif n == 0:
        print(0)
    else:
        p = int(math.log(n,4))

        l =[None for i in range(p)]
        x = n
        for i in range(p):
            l[i] = x // (4 ** (p - i))
            x = x % (4 ** (p - i))
        l.append(x)

        print(*l,sep="")

Submission status: Accepted

Solution code:
import sys
import math
def four_number(n,sum1,keta):
    ans=n//4
    amr=n%4
    sum1=sum1+amr*(math.pow(10,keta))
    keta=keta+1
    if(ans==0):
        return sum1
    else:
        return four_number(ans,sum1,keta)
        
    
i=0
sum1=0
keta=0
while i<2000:
    n=int(input())
    if(n==-1):
        break
    after_number=four_number(n,sum1,keta)
    print(round(after_number))

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if a == -1:
        break
    ans = []
    if a == 0:
        print(0)
    else:
        while a != 0:
            ans.append(a%4)
            a //= 4
        ans = list(map(str,ans))
        print("".join(ans[::-1]))

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


MAX = 10
POW = [1]*(MAX)

for i in range(1,MAX):
    POW[i] = POW[i-1]*4

while True:
    NUM = int(input())
    if NUM == -1:
        break
    elif NUM == 0:
        print("0")
        continue

    First = True
    for i in range(MAX-1,-1,-1):
        if POW[i] <= NUM:
            print("%d"%(NUM//POW[i]),end="")
            NUM %= POW[i]
            First = False
        else:
            if First: #
                pass
            else:
                print("0",end="")
    print()

Submission status: Accepted

Solution code:
def f(n):
  if int(n/4):
    return(f(int(n/4))+str(n%4))
  return str(n%4)
while 1:
  n=int(input())
  if n==-1:
    break
  print(f(n))

Submission status: Accepted

Solution code:
def translate(x):
    if int(x/4):
        return translate(int(x/4)) + str(x % 4)
    return str(x % 4)


while 1:
    n = int(input())
    if n == -1:
        break

    n4 = translate(n)
    print(n4)

Submission status: Accepted

Solution code:
def to_4(x):
    if x // 4:
        return to_4(x//4) + str(x%4)
    return str(x%4)

while True:
    n = int(input())
    if n == -1: break
    print(to_4(n))

Submission status: Runtime Error

Solution code:
 def f(n):
	a = ""
	while n>0:
		a += str(n%4)
		n //= 4
	return a[::-1]
	
while 1:
	n = input()
	if n == -1: break
	print f(n) if n > 0 else 0