結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-16 21:13:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 758 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 197,272 KB |
| 最終ジャッジ日時 | 2025-01-14 15:18:42 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()
const double PI = acos(-1);
long long solve() {
long long a, b, c;
cin >> a >> b >> c;
if (c == 1)
return -1;
vector<long long> ret;
long long cur = 0;
while (a > 1) {
ret.push_back(cur + (a + c - 2) / (c - 1));
if (a % c == 0) {
a /= c;
} else {
a -= a % c;
}
++cur;
}
ret.push_back(++cur);
long long r = *min_element(ret.begin(), ret.end());
return b * r;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int Q;
cin >> Q;
while (Q--) {
cout << solve() << endl;
}
return 0;
}