結果
| 問題 | 
                            No.1126 SUM
                             | 
                    
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-03-20 21:07:12 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 46 ms / 1,000 ms | 
| コード長 | 610 bytes | 
| コンパイル時間 | 168 ms | 
| コンパイル使用メモリ | 82,208 KB | 
| 実行使用メモリ | 62,052 KB | 
| 最終ジャッジ日時 | 2025-03-20 21:07:16 | 
| 合計ジャッジ時間 | 2,026 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 26 | 
ソースコード
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)
            
            
            
        
            
lam6er