結果
問題 | No.915 Plus Or Multiple Operation |
ユーザー |
![]() |
提出日時 | 2019-10-25 23:09:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 955 bytes |
コンパイル時間 | 1,523 ms |
コンパイル使用メモリ | 166,684 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 03:37:53 |
合計ジャッジ時間 | 2,048 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)#define itn int#define all(x) (x).begin(),(x).end()#define F first#define S secondconst long long INF = 1LL << 60;const int MOD = 1000000007;template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }int solve(int a,int b, int c){if(c == 1) return -1;int cnt = 0;while(a > (c-1)*2){if(a % c == 0) a/=c, cnt++;else {int res = a % c;cnt++;a -= res;}}while(a>0){a-= (c-1);cnt++;}return (cnt)*b;}signed main(void){int q; cin>>q;rep(i,q){int a,b,c; cin>>a>>b>>c;cout<<solve(a,b,c)<<endl;}}