結果

問題 No.915 Plus Or Multiple Operation
ユーザー simansiman
提出日時 2021-10-13 17:25:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 384 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 16,052 KB
最終ジャッジ日時 2023-10-17 19:07:45
合計ジャッジ時間 3,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,052 KB
testcase_01 AC 84 ms
16,052 KB
testcase_02 AC 84 ms
16,052 KB
testcase_03 AC 85 ms
16,052 KB
testcase_04 AC 85 ms
16,052 KB
testcase_05 AC 84 ms
16,048 KB
testcase_06 AC 85 ms
16,052 KB
testcase_07 AC 84 ms
16,052 KB
testcase_08 AC 83 ms
16,052 KB
testcase_09 AC 84 ms
16,052 KB
testcase_10 AC 84 ms
16,052 KB
testcase_11 AC 85 ms
16,052 KB
testcase_12 AC 85 ms
16,052 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

Q = gets.to_i

Q.times do
  a, b, c = gets.split.map(&:to_i)
  ans = Float::INFINITY
  cnt = 0

  if c == 1
    ans = -1
  else
    while a > 0
      x = b * (cnt + Rational(a, c - 1).ceil)
      ans = x if ans > x

      if a < c
        a = 0
      elsif a % c != 0
        a -= a % c
      else
        a /= c
      end

      cnt += 1
    end
  end

  puts [ans, cnt * b].min
end
0