結果

問題 No.915 Plus Or Multiple Operation
ユーザー convexineqconvexineq
提出日時 2019-10-25 22:05:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 526 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 308,864 KB
最終ジャッジ日時 2024-11-07 03:30:20
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#from math import gcd

def ans(a,b,c):
    if a == 0: return 0
    elif a%c==0:
        return ans(a//c,b,c) +b
    else:
        if a < c: return b
        r = a%c
        if r == c-1:
            return ans(a//c*c,b,c) + b
        else:
            return min(ans(a//c*c,b,c)+b, ans(a-(r+c),b,c)+2*b)


q = int(input())
for _ in range(q):
    a,b,c = [int(i) for i in readline().split()]
    
    print(ans(a,b,c))


0