結果

問題 No.782 マイナス進数
コンテスト
ユーザー kohei2019
提出日時 2022-04-09 12:20:32
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 655 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 244 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 81,536 KB
最終ジャッジ日時 2026-05-23 06:00:28
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

T,B = map(int,input().split())
A = abs(B)
for i in range(T):
    N = int(input())
    if N == 0:
        print(0)
        continue
    ls = []
    while N > 0:
        ls.append(N%A)
        N //= A
    ls2 = [0]*40
    for j in range(len(ls)):
        ls2[j] = ls[j]
    for j in range(39):
        if j % 2 == 0:
            ls2[j+1] += ls2[j]//A
            ls2[j] = ls2[j]%A
        else:
            ls2[j+1] += ls2[j]//A
            ls2[j] = ls2[j]%A
            if not ls2[j]==0:
                ls2[j] = A-ls2[j]
                ls2[j+1] += 1
    while ls2[-1] == 0:
        ls2.pop()
    ls2.reverse()
    print(*ls2,sep='')
            
        
0