結果

問題 No.915 Plus Or Multiple Operation
ユーザー H20
提出日時 2021-10-01 16:10:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2024-07-19 04:00:46
合計ジャッジ時間 1,596 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

Q = int(input())
for _ in range(Q):
    a,b,c=map(int,input().split())
    if c==1:
        print(-1)
    else:
        cnt = 0
        while a>0:
            if c<=a<2*c-1:
                cnt+=2
                a=0
            elif a%c>0:
                cnt+=1
                a-=a%c
            else:
                a=a//c
                cnt+=1
        print(cnt*b)



0