結果

問題 No.782 マイナス進数
ユーザー AEnAEn
提出日時 2022-06-02 17:48:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2023-10-21 01:13:42
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,556 KB
testcase_01 AC 39 ms
53,556 KB
testcase_02 AC 131 ms
76,336 KB
testcase_03 AC 134 ms
76,328 KB
testcase_04 AC 137 ms
76,404 KB
testcase_05 AC 132 ms
76,340 KB
testcase_06 AC 130 ms
76,328 KB
testcase_07 AC 147 ms
76,340 KB
testcase_08 AC 132 ms
76,348 KB
testcase_09 AC 127 ms
76,328 KB
testcase_10 AC 130 ms
76,324 KB
testcase_11 AC 153 ms
76,928 KB
testcase_12 AC 142 ms
76,820 KB
testcase_13 AC 184 ms
76,488 KB
testcase_14 AC 139 ms
76,332 KB
testcase_15 AC 146 ms
76,356 KB
testcase_16 AC 149 ms
76,928 KB
testcase_17 AC 166 ms
76,412 KB
testcase_18 AC 142 ms
76,340 KB
testcase_19 AC 150 ms
76,460 KB
testcase_20 AC 148 ms
76,484 KB
testcase_21 AC 175 ms
76,584 KB
testcase_22 AC 144 ms
76,484 KB
testcase_23 AC 138 ms
76,368 KB
testcase_24 AC 189 ms
76,912 KB
testcase_25 AC 147 ms
76,828 KB
testcase_26 AC 150 ms
76,452 KB
testcase_27 AC 152 ms
76,460 KB
testcase_28 AC 143 ms
76,368 KB
testcase_29 AC 41 ms
53,556 KB
testcase_30 AC 40 ms
53,556 KB
testcase_31 AC 43 ms
55,604 KB
testcase_32 AC 55 ms
64,500 KB
testcase_33 AC 41 ms
53,556 KB
testcase_34 AC 42 ms
53,556 KB
testcase_35 AC 41 ms
53,556 KB
testcase_36 AC 41 ms
53,556 KB
testcase_37 AC 42 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+2, -1, -1):
        p = pow(-B, i)
        res += str(N//p)
        N %= p
    ans = [0]*(l+10)
    res = res[::-1]
    for j in range(l+3):
        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