結果

問題 No.915 Plus Or Multiple Operation
ユーザー IKyoproIKyopro
提出日時 2019-10-25 21:51:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 401 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 72,544 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:36:51
合計ジャッジ時間 1,247 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll solve(ll a,ll b,ll c){
    if(c==1) return a*b;
    if(a<=c) return b;
    ll r = a%c,k = a/c;
    ll cnt = (r!=0) + (k!=1);
    return cnt*b+solve(k,b,c);
}

int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        cout << solve(a,b,c) << endl;
    }   
}
0