結果

問題 No.782 マイナス進数
ユーザー nebukuro09nebukuro09
提出日時 2019-01-12 11:48:43
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 443 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 77,512 KB
実行使用メモリ 80,324 KB
最終ジャッジ日時 2023-08-22 15:14:01
合計ジャッジ時間 7,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
76,348 KB
testcase_01 AC 73 ms
76,344 KB
testcase_02 AC 140 ms
80,264 KB
testcase_03 AC 131 ms
80,180 KB
testcase_04 AC 130 ms
80,072 KB
testcase_05 AC 130 ms
80,096 KB
testcase_06 AC 132 ms
80,060 KB
testcase_07 AC 135 ms
79,772 KB
testcase_08 AC 127 ms
79,920 KB
testcase_09 AC 131 ms
79,956 KB
testcase_10 AC 128 ms
80,324 KB
testcase_11 AC 135 ms
79,832 KB
testcase_12 AC 130 ms
79,708 KB
testcase_13 AC 144 ms
80,120 KB
testcase_14 AC 128 ms
79,916 KB
testcase_15 AC 132 ms
79,832 KB
testcase_16 AC 130 ms
79,800 KB
testcase_17 AC 136 ms
80,152 KB
testcase_18 AC 128 ms
79,996 KB
testcase_19 AC 134 ms
79,932 KB
testcase_20 AC 128 ms
79,664 KB
testcase_21 AC 135 ms
79,720 KB
testcase_22 AC 138 ms
80,128 KB
testcase_23 AC 127 ms
79,940 KB
testcase_24 AC 141 ms
80,056 KB
testcase_25 AC 129 ms
80,076 KB
testcase_26 AC 133 ms
79,860 KB
testcase_27 AC 130 ms
79,808 KB
testcase_28 AC 136 ms
80,224 KB
testcase_29 AC 73 ms
76,532 KB
testcase_30 AC 72 ms
76,380 KB
testcase_31 AC 73 ms
76,640 KB
testcase_32 AC 80 ms
78,992 KB
testcase_33 AC 73 ms
76,296 KB
testcase_34 AC 74 ms
76,620 KB
testcase_35 AC 75 ms
76,288 KB
testcase_36 AC 75 ms
76,168 KB
testcase_37 AC 73 ms
76,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T, B = map(int, raw_input().split())
B *= -1

def solve():
    N = int(raw_input())

    if N == 0:
        print 0
        return

    ans = []
    t = 0
    while N != 0:
        m = N % B
        if t == 0 or m == 0:
            ans.append(m)
            N /= B
        else:
            ans.append(B - m)
            N += B - m
            N /= B
        t ^= 1
    print "".join(map(str, reversed(ans)))


for _ in xrange(T):
    solve()
0