結果

問題 No.915 Plus Or Multiple Operation
ユーザー tamatotamato
提出日時 2019-10-25 23:00:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 509 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 53,408 KB
最終ジャッジ日時 2024-04-24 18:47:50
合計ジャッジ時間 1,313 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,592 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 40 ms
51,968 KB
testcase_03 AC 41 ms
52,224 KB
testcase_04 WA -
testcase_05 AC 40 ms
52,480 KB
testcase_06 AC 39 ms
52,608 KB
testcase_07 AC 40 ms
52,480 KB
testcase_08 AC 38 ms
52,608 KB
testcase_09 AC 39 ms
52,480 KB
testcase_10 WA -
testcase_11 AC 40 ms
52,480 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

q = int(input())
for _ in range(q):
    a, b, c = map(int, input().split())
    if c == 1:
        print(-1)
        continue
    num = []
    while True:
        a, mod = divmod(a, c)
        num.append(mod)
        if a == 0:
            break
    # print(num)
    if len(num) == 1:
        print(1)
        continue
    ans = b * len(num) - b
    for i in range(len(num)):
        if num[i] != 0:
            ans += b
    if num[-1] == 1 and 0 < num[-2] < c-1:
        ans -= b
    print(ans)
0