結果

問題 No.915 Plus Or Multiple Operation
ユーザー 👑 rin204rin204
提出日時 2022-07-05 21:17:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 71,404 KB
最終ジャッジ日時 2023-08-22 11:12:11
合計ジャッジ時間 2,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,228 KB
testcase_01 AC 75 ms
71,308 KB
testcase_02 AC 76 ms
71,264 KB
testcase_03 AC 73 ms
71,176 KB
testcase_04 AC 75 ms
71,360 KB
testcase_05 AC 73 ms
71,288 KB
testcase_06 AC 76 ms
71,264 KB
testcase_07 AC 75 ms
71,404 KB
testcase_08 AC 77 ms
71,224 KB
testcase_09 AC 76 ms
71,120 KB
testcase_10 AC 75 ms
71,124 KB
testcase_11 AC 75 ms
71,268 KB
testcase_12 AC 76 ms
71,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(a, b, c):
    if c == 1:
        return -1
    ans = 0
    while a > 0:
        if a <= c - 1:
            ans += 1
            a = 0
        elif a <= 2 * (c - 1):
            ans += 2
            a = 0
        elif a % c == 0:
            ans += 1
            a //= c
        else:
            ans += 1
            a = a // c * c
    return ans * b

for _ in range(int(input())):
    print(solve(*map(int, input().split())))
    
0