結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-11 22:01:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 994 bytes |
| コンパイル時間 | 1,652 ms |
| コンパイル使用メモリ | 166,780 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-10-11 22:01:22 |
| 合計ジャッジ時間 | 2,913 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 100010;
ll n, m, res;
ll fac[N], inv[N], finv[N];
constexpr ll INF=1e16;
void init()
{
fac[0] = fac[1] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
for (int i = 2; i < N; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i < N; i++) finv[i] = finv[i - 1] * inv[i] % mod;
}
ll C(ll x, ll y)
{
if (x < y) return 0;
return fac[x] * finv[x - y] % mod * finv[y] % mod;
}
ll ksm(ll x, ll y)
{
ll res;
res = 1;
while (y)
{
res = (y & 1) ? res * x % mod : res;
x = x * x % mod;
y >>= 1;
}
return res;
}
int main()
{
init();
scanf("%lld%lld", &n, &m);
if (n < m) printf("0\n"), exit(0);
res = 0;
for (int i = 0; i <= m; i++)
{
if ((m - i) & 1) res = (res - C(m, i) * ksm(i, n) % mod + mod) % mod;
else res = (res + C(m, i) * ksm(i, n) % mod) % mod;
}
printf("%lld\n", res);
return 0;
}