結果
問題 | No.391 CODING WAR |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:11:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 455 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 63,256 KB |
最終ジャッジ日時 | 2025-03-20 21:12:34 |
合計ジャッジ時間 | 2,717 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
MOD = 10**9 + 7def main():import sysN, M = map(int, sys.stdin.readline().split())if M > N:print(0)return# Precompute factorial and inverse factorial modulo MODfact = [1] * (M + 1)for i in range(1, M + 1):fact[i] = fact[i - 1] * i % MODinv_fact = [1] * (M + 1)inv_fact[M] = pow(fact[M], MOD - 2, MOD)for i in range(M - 1, -1, -1):inv_fact[i] = inv_fact[i + 1] * (i + 1) % MODresult = 0for k in range(0, M + 1):# Compute sign (-1)^k mod MODsign = pow(-1, k, MOD)# Compute combination C(M, k)comb = fact[M] * inv_fact[k] % MODcomb = comb * inv_fact[M - k] % MOD# Compute (M -k)^N mod MODbase = M - kpower = pow(base, N, MOD)# Compute termterm = sign * comb % MODterm = term * power % MOD# Add to resultresult = (result + term) % MODprint(result)if __name__ == '__main__':main()