結果

問題 No.1126 SUM
ユーザー lam6er
提出日時 2025-03-20 21:07:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 60 ms / 1,000 ms
コード長 610 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 231 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 85,068 KB
最終ジャッジ日時 2026-07-07 12:50:59
合計ジャッジ時間 3,608 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

MOD = 10**9 + 7

n, m = map(int, input().split())

k = n + 1
target = m + 1

if k > target:
    print(0)
else:
    # Precompute factorial up to target
    max_fact = target
    fact = [1] * (max_fact + 1)
    for i in range(1, max_fact + 1):
        fact[i] = fact[i-1] * i % MOD
    
    # Precompute inverse factorial
    inv_fact = [1] * (max_fact + 1)
    inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD)
    for i in range(max_fact - 1, -1, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
    
    ans = fact[target] * inv_fact[k] % MOD
    ans = ans * inv_fact[target - k] % MOD
    print(ans)
0