結果

問題 No.915 Plus Or Multiple Operation
ユーザー Mayimg
提出日時 2019-10-27 07:47:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 448 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 193,180 KB
最終ジャッジ日時 2025-01-08 01:59:34
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
long long solve () {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c == 1) return -1;
  for (int i = 1; ; i++) {
    if ((c - 1) * 2 >= a) a -= c - 1;
    else if (a % c == 0) a /= c;
    else a -= a % c;
    if (a <= 0) return b * i;
  }
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int q;
  cin >> q;
  while (q--) cout << solve() << '\n';
  return 0;
}
0