結果

問題 No.782 マイナス進数
ユーザー AEnAEn
提出日時 2022-06-02 17:42:33
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,512 KB
実行使用メモリ 77,032 KB
最終ジャッジ日時 2023-10-21 01:13:36
合計ジャッジ時間 6,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,552 KB
testcase_01 AC 39 ms
53,552 KB
testcase_02 AC 133 ms
76,384 KB
testcase_03 AC 150 ms
76,608 KB
testcase_04 AC 142 ms
76,344 KB
testcase_05 AC 132 ms
76,356 KB
testcase_06 AC 129 ms
76,340 KB
testcase_07 AC 146 ms
76,480 KB
testcase_08 AC 131 ms
76,368 KB
testcase_09 WA -
testcase_10 AC 131 ms
76,332 KB
testcase_11 AC 155 ms
76,940 KB
testcase_12 WA -
testcase_13 AC 184 ms
76,908 KB
testcase_14 AC 137 ms
76,344 KB
testcase_15 AC 145 ms
76,352 KB
testcase_16 AC 147 ms
77,008 KB
testcase_17 AC 163 ms
76,460 KB
testcase_18 AC 139 ms
76,348 KB
testcase_19 AC 150 ms
76,360 KB
testcase_20 AC 142 ms
76,384 KB
testcase_21 AC 175 ms
77,032 KB
testcase_22 AC 145 ms
76,356 KB
testcase_23 AC 136 ms
76,364 KB
testcase_24 AC 187 ms
76,488 KB
testcase_25 AC 146 ms
76,952 KB
testcase_26 AC 149 ms
76,484 KB
testcase_27 AC 154 ms
77,000 KB
testcase_28 AC 139 ms
76,372 KB
testcase_29 WA -
testcase_30 AC 40 ms
53,556 KB
testcase_31 AC 43 ms
55,604 KB
testcase_32 AC 55 ms
64,444 KB
testcase_33 AC 40 ms
53,556 KB
testcase_34 AC 41 ms
53,556 KB
testcase_35 AC 41 ms
53,556 KB
testcase_36 AC 40 ms
53,556 KB
testcase_37 AC 41 ms
53,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
T, B = map(int,input().split())
for _ in range(T):
    N = int(input())
    if N == 0:
        print(0)
        continue
    res = ''
    l = int(math.log(N)/math.log(-B))
    for i in range(l, -1, -1):
        p = pow(-B, i)
        res += str(N//p)
        N %= p
    ans = [0]*(l+10)
    res = res[::-1]
    for j in range(l+1):
        if int(res[j])>0:
            if j%2 == 0:
                ans[j] += int(res[j])
            else:
                ans[j+1] += 1
                ans[j] += (-B-int(res[j]))
    for k in range(len(ans)-2):
        a, b = ans[k]//(-B), ans[k]%(-B)
        if ans[k+1] >= a:
            ans[k+1] -= a
        else:
            ans[k+2] += 1
            ans[k+1] += (-B-a)
        ans[k] = str(b)
    print(int(''.join(ans[:-2])[::-1]))
0