結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

ll solve(int a, int b, int c) { 
  if (c == 1) { return -1; }
  // cerr << a << " " << b << " " << c << endl;
  ll ret = 0;
  int tmp = a;
  while (tmp > 0) {
    // cerr << tmp << " ";
    if (tmp < 2*c-1) {
      tmp -= c-1;
    }
    else if (tmp % c == 0) {
      tmp /= c;
    }
    else { tmp -= tmp%c; }
    ret += 1;
  }
  // cerr << endl;
  // cerr << ret << endl;
  return ret*(ll)b;
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    ll ans = solve(a, b, c);
    cout << ans << endl;
  }
}

0