結果

問題 No.673 カブトムシ
ユーザー simansiman
提出日時 2021-12-16 01:56:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 11,284 KB
実行使用メモリ 15,292 KB
最終ジャッジ日時 2023-10-01 04:35:28
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,028 KB
testcase_01 AC 82 ms
15,052 KB
testcase_02 AC 81 ms
15,104 KB
testcase_03 AC 80 ms
15,088 KB
testcase_04 AC 80 ms
15,020 KB
testcase_05 AC 81 ms
15,264 KB
testcase_06 AC 80 ms
15,120 KB
testcase_07 AC 81 ms
15,260 KB
testcase_08 AC 84 ms
15,260 KB
testcase_09 AC 80 ms
15,032 KB
testcase_10 AC 85 ms
15,080 KB
testcase_11 AC 80 ms
15,076 KB
testcase_12 AC 80 ms
15,028 KB
testcase_13 AC 82 ms
15,096 KB
testcase_14 AC 81 ms
15,028 KB
testcase_15 AC 80 ms
14,992 KB
testcase_16 AC 80 ms
15,180 KB
testcase_17 AC 81 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def mod_pow(n, mod)
    x = self
    res = 1

    while n > 0
      res = res * x % mod if n[0] == 1
      x = x * x % mod
      n >>= 1
    end

    res
  end

  def mod_inverse(mod)
    mod_pow(mod - 2, mod)
  end
end

B, C, D = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

def sum(a, r, n, mod)
  return a % mod if n == 1

  x = sum(a, r, n / 2, mod)
  ret = (x + r.pow(n / 2, mod) * x) % mod
  ret = (a + r * ret) % mod if n.odd?

  ret
end

S = sum(C, C, D, MOD)

puts (B * S) % MOD
0