結果

問題 No.915 Plus Or Multiple Operation
ユーザー kuhakukuhaku
提出日時 2019-10-25 22:00:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 164,784 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 00:21:35
合計ジャッジ時間 2,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

ll query(int a, int b, int c){
	if(c == 1) return -1;
	ll ans = 0;
	while(a){
		if(a < c){
			ans += b;
			a = 0;
		}else if(a < 2*c-1){
			ans += b;
			a -= c-1;
		}else if(a%c){
			ans += b;
			a -= a%c;
		}else{
			ans += b;
			a /= c;
		}
	}

	return ans;
}

int main(void){
	int q;
	cin >> q;

	rep(i, q){
		int a, b, c;
		cin >> a >> b >> c;
		co(query(a, b, c));
	}

	return 0;
}
0