結果

問題 No.1126 SUM
ユーザー simansiman
提出日時 2021-02-12 02:14:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 825 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 11,252 KB
実行使用メモリ 17,964 KB
最終ジャッジ日時 2023-09-25 15:43:36
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
17,488 KB
testcase_01 AC 128 ms
17,720 KB
testcase_02 AC 100 ms
16,700 KB
testcase_03 AC 92 ms
16,020 KB
testcase_04 AC 124 ms
17,804 KB
testcase_05 AC 115 ms
17,424 KB
testcase_06 AC 104 ms
16,836 KB
testcase_07 AC 122 ms
17,136 KB
testcase_08 AC 122 ms
17,348 KB
testcase_09 AC 122 ms
17,352 KB
testcase_10 AC 110 ms
17,388 KB
testcase_11 AC 120 ms
17,204 KB
testcase_12 AC 129 ms
17,964 KB
testcase_13 AC 106 ms
16,752 KB
testcase_14 AC 104 ms
16,776 KB
testcase_15 AC 101 ms
17,000 KB
testcase_16 AC 124 ms
17,616 KB
testcase_17 AC 104 ms
16,796 KB
testcase_18 AC 118 ms
17,012 KB
testcase_19 AC 120 ms
17,604 KB
testcase_20 AC 104 ms
16,588 KB
testcase_21 AC 119 ms
17,668 KB
testcase_22 AC 110 ms
17,088 KB
testcase_23 AC 126 ms
17,656 KB
testcase_24 AC 116 ms
16,984 KB
testcase_25 AC 143 ms
17,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

MOD = 10 ** 9 + 7

class ModInteger
  attr_reader :fac, :inv, :finv, :mod

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end

  def permutation(n, k = n)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[n - k] % mod) % mod
  end

  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

N, M = gets.split.map(&:to_i)

mi = ModInteger.new(M + 1)
ans = 0

N.upto(M) do |x|
  ans += mi.combination(x, N)
  ans %= MOD
end

puts ans
0