結果

問題 No.915 Plus Or Multiple Operation
ユーザー もりを
提出日時 2019-10-25 21:44:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 390 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 81,964 KB
実行使用メモリ 53,956 KB
最終ジャッジ日時 2024-11-07 03:24:00
合計ジャッジ時間 1,841 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
for i in range(n):
    a,b,c = map(int,input().split())
    if c == 1:
        print(-1)
        continue
    if c == 2:
        print(a * b)
        continue
    x = 0
    y = 10 ** 100
    while a > 0:
        y = min(y, x + b * ((a + c - 2) // (c - 1)))
        if a % c == 0:
            a //= c
        else:
            a -= a % c
        x += b
    print(min(x, y))
0