結果

問題 No.915 Plus Or Multiple Operation
ユーザー Ogtsn99Ogtsn99
提出日時 2019-10-25 23:09:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 1,447 ms
コンパイル使用メモリ 165,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 00:29:47
合計ジャッジ時間 2,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int solve(int a,int b, int c){
    if(c == 1) return -1;
    int cnt = 0;
    while(a > (c-1)*2){
        if(a % c == 0) a/=c, cnt++;
        else {
            int res = a % c;
            cnt++;
            a -= res;
        }
    }
    while(a>0){
        a-= (c-1);
        cnt++;
    }

    return (cnt)*b;
}
signed main(void){
    int q; cin>>q;
    rep(i,q){
        int a,b,c; cin>>a>>b>>c;
        cout<<solve(a,b,c)<<endl;
    }
}
0