結果

問題 No.915 Plus Or Multiple Operation
ユーザー tamatotamato
提出日時 2019-10-25 23:00:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 509 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 54,776 KB
最終ジャッジ日時 2024-11-07 03:37:28
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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