結果

問題 No.915 Plus Or Multiple Operation
ユーザー tamatotamato
提出日時 2019-10-25 22:09:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 52,736 KB
最終ジャッジ日時 2024-04-24 18:42:04
合計ジャッジ時間 1,995 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 41 ms
52,352 KB
testcase_02 WA -
testcase_03 AC 42 ms
52,224 KB
testcase_04 AC 41 ms
52,352 KB
testcase_05 AC 42 ms
52,608 KB
testcase_06 AC 41 ms
52,608 KB
testcase_07 AC 40 ms
52,096 KB
testcase_08 WA -
testcase_09 AC 40 ms
52,196 KB
testcase_10 AC 45 ms
52,224 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

q = int(input())
for _ in range(q):
    a, b, c = map(int, input().split())
    if c == 1:
        print(a*b)
        continue
    num = []
    while True:
        a, mod = divmod(a, c)
        num.append(mod)
        if a == 0:
            break
    num.reverse()
    i = 0
    ans = 0
    while True:
        if num[i] == 0:
            if i < len(num) - 1:
                ans += b
            else:
                break
            i += 1
        else:
            if i == len(num) - 1:
                ans += b
                break
            else:
                if num[i+1] != 0:
                    if (num[i]*c+num[i+1]-1)//(c-1)+1 <= 2:
                        ans += 2*b
                        i += 2
                        if i == len(num):
                            break
                        else:
                            ans += b
                    else:
                        ans += 2*b
                        i += 1
                else:
                    ans += 2 * b
                    i += 1
    print(ans)

0