結果
問題 | No.915 Plus Or Multiple Operation |
ユーザー | soto800 |
提出日時 | 2019-10-25 23:00:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 679 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 157,952 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-07 03:37:24 |
合計ジャッジ時間 | 1,784 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
#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; if(c==1)return -1; 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; }