結果

問題 No.782 マイナス進数
ユーザー kohei2019kohei2019
提出日時 2022-04-09 12:20:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,144 KB
最終ジャッジ日時 2024-11-29 09:47:39
合計ジャッジ時間 5,791 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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