結果

問題 No.915 Plus Or Multiple Operation
ユーザー soto800soto800
提出日時 2019-10-25 22:49:03
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 658 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 158,848 KB
実行使用メモリ 16,960 KB
最終ジャッジ日時 2024-04-24 18:47:24
合計ジャッジ時間 7,473 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

lli b,c;

lli calc(lli a){
	lli next=0;

	while(1){
		if(DEBUG)cout<<a<<endl;
		if(a<c){
			next+=b;
			break;
		}
		if(a<=2*(c-1)){
			next+= (2*b);
			break;
		}
		next+=b;
		if(a%c!=0)next+=b;
		a /= c;
	}

	return next;
}
void solve(){
	lli a;
	cin>>a>>b>>c;

	/*逆からやるとよさそう*/
	cout<<calc(a)<<endl;
}

signed main(){

	lli q;
	cin>>q;

	REP(i,0,q)solve();

	return 0;
}
0