結果

問題 No.1035 Color Box
ユーザー irumo8202
提出日時 2022-01-26 17:46:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 78,848 KB
最終ジャッジ日時 2024-12-23 09:58:45
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
limit = 2 * 10 ** 5
fact = [1] * (limit + 1)
invfact = [1] * (limit + 1)

for i in range(2, limit + 1):
    fact[i] = fact[i - 1] * i % MOD

invfact[-1] = pow(fact[-1], MOD - 2, MOD)

for i in range(limit - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD


def nCk(n, k):
    return fact[n] * invfact[n - k] % MOD * invfact[k] % MOD


ans = 0

for i in range(M + 1):
    ans += pow(-1, M - i, MOD) * nCk(M, i) * pow(i, N, MOD)
    ans %= MOD

print(ans)
0