結果

問題 No.782 マイナス進数
ユーザー MShinyaMShinya
提出日時 2019-02-05 18:26:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 8,460 KB
最終ジャッジ日時 2023-08-30 23:55:17
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,960 KB
testcase_01 AC 15 ms
8,052 KB
testcase_02 AC 89 ms
8,008 KB
testcase_03 AC 101 ms
8,100 KB
testcase_04 AC 105 ms
8,096 KB
testcase_05 AC 92 ms
7,976 KB
testcase_06 AC 90 ms
8,144 KB
testcase_07 AC 131 ms
8,040 KB
testcase_08 AC 96 ms
8,008 KB
testcase_09 AC 91 ms
8,028 KB
testcase_10 AC 89 ms
7,976 KB
testcase_11 AC 125 ms
7,968 KB
testcase_12 AC 115 ms
8,292 KB
testcase_13 AC 208 ms
8,436 KB
testcase_14 AC 112 ms
8,292 KB
testcase_15 AC 121 ms
8,340 KB
testcase_16 AC 116 ms
8,072 KB
testcase_17 AC 164 ms
8,428 KB
testcase_18 AC 114 ms
8,356 KB
testcase_19 AC 138 ms
8,460 KB
testcase_20 AC 115 ms
8,440 KB
testcase_21 AC 149 ms
8,032 KB
testcase_22 AC 120 ms
8,424 KB
testcase_23 AC 106 ms
8,024 KB
testcase_24 AC 203 ms
8,056 KB
testcase_25 AC 114 ms
7,976 KB
testcase_26 AC 130 ms
7,972 KB
testcase_27 AC 124 ms
8,032 KB
testcase_28 AC 110 ms
8,000 KB
testcase_29 AC 15 ms
8,056 KB
testcase_30 AC 16 ms
8,008 KB
testcase_31 AC 16 ms
8,064 KB
testcase_32 AC 17 ms
7,976 KB
testcase_33 AC 16 ms
8,060 KB
testcase_34 AC 16 ms
7,952 KB
testcase_35 AC 16 ms
8,016 KB
testcase_36 AC 17 ms
8,140 KB
testcase_37 AC 16 ms
8,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math


def division(a, b):
    if b == 0:
        raise ZeroDivisionError()
    if a == 0:
        return 0, 0
    if a > 0 and b > 0:
        q = math.floor(a / b)
        return q, a - b * q
    if a > 0 and b < 0:
        q = math.ceil(a / b)
        return q, a - b * q
    if a < 0 and b > 0:
        q = math.floor(a / b)
        return q, a - b * q
    if a < 0 and b < 0:
        q = math.ceil(a / b)
        return q, a - b * q


def Ans(N, B):
    ans = ''
    while(N != 0):
        N, r = division(N, B)
        ans += str(r)
    if ans:
        print(ans[::-1])
    else:
        print(0)


if __name__ == '__main__':
    T, B = map(int, input().split())
    for _ in range(T):
        N = int(input())
        Ans(N, B)
0