結果

問題 No.782 マイナス進数
ユーザー ayaoniayaoni
提出日時 2020-12-08 14:11:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 75,836 KB
最終ジャッジ日時 2023-10-17 17:12:58
合計ジャッジ時間 3,800 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,528 KB
testcase_01 AC 36 ms
53,528 KB
testcase_02 AC 61 ms
72,768 KB
testcase_03 AC 62 ms
72,808 KB
testcase_04 AC 64 ms
74,100 KB
testcase_05 AC 61 ms
72,768 KB
testcase_06 AC 61 ms
72,768 KB
testcase_07 AC 70 ms
75,744 KB
testcase_08 AC 62 ms
72,768 KB
testcase_09 AC 61 ms
72,764 KB
testcase_10 AC 61 ms
72,764 KB
testcase_11 AC 71 ms
75,836 KB
testcase_12 AC 69 ms
75,764 KB
testcase_13 AC 81 ms
75,732 KB
testcase_14 AC 70 ms
75,760 KB
testcase_15 AC 70 ms
75,832 KB
testcase_16 AC 69 ms
75,764 KB
testcase_17 AC 74 ms
75,752 KB
testcase_18 AC 69 ms
75,764 KB
testcase_19 AC 72 ms
75,760 KB
testcase_20 AC 67 ms
75,760 KB
testcase_21 AC 73 ms
75,752 KB
testcase_22 AC 69 ms
75,760 KB
testcase_23 AC 63 ms
74,384 KB
testcase_24 AC 82 ms
75,752 KB
testcase_25 AC 68 ms
75,756 KB
testcase_26 AC 71 ms
75,736 KB
testcase_27 AC 69 ms
75,772 KB
testcase_28 AC 67 ms
75,736 KB
testcase_29 AC 37 ms
53,528 KB
testcase_30 AC 36 ms
53,528 KB
testcase_31 AC 38 ms
53,528 KB
testcase_32 AC 43 ms
59,980 KB
testcase_33 AC 37 ms
53,528 KB
testcase_34 AC 37 ms
53,528 KB
testcase_35 AC 37 ms
53,528 KB
testcase_36 AC 36 ms
53,528 KB
testcase_37 AC 37 ms
53,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


T,B = MI()
B = -B

for _ in range(T):
    N = I()
    if N == 0:
        print(0)
        continue
    b = 0
    ANS = []
    while N:
        if b == 0:
            r = N % B
            N //= B
            ANS.append(str(r))
        else:
            r = (-N) % B
            N = (N+r)//B
            ANS.append(str(r))
        b = 1-b
    ANS.reverse()
    print(''.join(ANS))
0