結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-27 11:06:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 640 bytes |
| コンパイル時間 | 1,014 ms |
| コンパイル使用メモリ | 66,176 KB |
| 最終ジャッジ日時 | 2025-01-10 02:26:56 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <iostream>
using lint = long long;
void solve() {
lint a, b, c;
std::cin >> a >> b >> c;
if (c == 1) {
std::cout << -1 << std::endl;
return;
}
lint ans = a, cost = 0;
while (a > 0) {
ans = std::min(ans, cost + (a + c - 2) / (c - 1));
if (a % c != 0) ++cost;
a -= a % c;
ans = std::min(ans, cost + (a + c - 2) / (c - 1));
++cost;
a /= c;
}
std::cout << ans * b << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int q;
std::cin >> q;
while (q--) solve();
return 0;
}