結果

問題 No.915 Plus Or Multiple Operation
ユーザー tonyu0tonyu0
提出日時 2019-10-26 00:19:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 63,832 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 03:40:46
合計ジャッジ時間 1,113 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;
ll q, a, b, c;

int main() {
  cin >> q;
  while(q--) {
    cin >> a >> b >> c;
    if(c == 1) {
      cout << -1 << '\n';
      continue;
    }

    ll ans = INF, cnt = 0;
    while(a) {
      ans = min(ans, cnt + (a + c - 2) / (c - 1));
      if(a % c) a -= a % c;
      else a /= c;
      ++cnt;
    }
    cout << ans * b << '\n';
  }
  return 0;
}
0