結果

問題 No.915 Plus Or Multiple Operation
ユーザー tpyneriver
提出日時 2019-10-12 20:34:13
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 500 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 848,208 KB
最終ジャッジ日時 2024-11-07 03:19:56
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 4 MLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

Q = int(readline())
Ans = [None]*Q

for qu in range(Q):
    a, b, c = map(int, readline().split())
    if c == 1:
        Ans[qu] = -1
        continue   
    cnt = 0
    twosteps = set(range(c+1, 2*c-1))
    while a > 0:
        if a in twosteps:
            cnt += 2
            a = 0
            continue
        elif a % c:
            a -= a%c
        else:
            a //= c
        cnt += 1
    
    Ans[qu] = b*cnt

print('\n'.join(map(str, Ans)))
0