結果

問題 No.915 Plus Or Multiple Operation
ユーザー kuhakukuhaku
提出日時 2019-10-25 21:53:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 786 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 164,164 KB
実行使用メモリ 12,212 KB
最終ジャッジ日時 2023-08-07 00:19:04
合計ジャッジ時間 7,917 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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){
	ll ans = 0;
	while(a){
		if(a%c){
			ans += b;
			a -= a%c;
		}else if(a < 2*c-1){
			ans += b;
			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