結果
問題 | No.915 Plus Or Multiple Operation |
ユーザー |
![]() |
提出日時 | 2019-10-25 21:55:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 792 bytes |
コンパイル時間 | 1,530 ms |
コンパイル使用メモリ | 166,752 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 03:27:48 |
合計ジャッジ時間 | 2,129 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int solve() { int a,b,c; cin>>a>>b>>c; if(c==1) return -1; int res=0; while(a>=c){ int r=a%c; if(r!=0){ if(a-(c-1)<c){ res++; a-=(c-1); }else{ res+=(r+c-2)/(c-1); a-=r; } }else{ a/=c; res++; } } return b*(res+1); } signed main() { cin.tie(0); ios::sync_with_stdio(false); int Q; cin>>Q; while(Q--){ cout<<solve()<<endl; } return 0; }