結果

問題 No.915 Plus Or Multiple Operation
ユーザー theory_and_metheory_and_me
提出日時 2019-10-25 23:18:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,378 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 162,340 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:48:38
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll Q;
    cin >> Q;
    while(Q--){
    	ll A, B, C;
    	cin >> A >> B >> C;

    	if(C==0){
    		cout << -1 << endl;
    		return 0;
    	}

    	ll cnt = 0;
    	ll res = (1ll<<60);
    	while(A>0){
    		res = min(res, cnt+(A+(C-2))/(C-1));
    		if(A%C){
    			A -= (A%C);
    		}else{
    			A /= C;
    		}
    		cnt++;
    	}
    	res = min(res, cnt);
    	cout << res*B << endl;
    }
    return 0;
}
0