結果
| 問題 |
No.2058 Binary String
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-08-21 17:44:07 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 951 bytes |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 8,564 KB |
| 最終ジャッジ日時 | 2024-10-10 06:17:15 |
| 合計ジャッジ時間 | 1,441 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <stdio.h>
const int Mod = 998244353;
long long fact[1000001], fact_inv[1000001];
long long div_mod(long long x, long long y, long long z)
{
if (x % y == 0) return x / y;
else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}
long long pow_mod(int n, long long k)
{
long long N, ans = 1;
for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
return ans;
}
long long combination(int n, int k)
{
if (k < 0 || n < k) return 0;
return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}
int main()
{
int N, K;
scanf("%d %d", &N, &K);
int i;
for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
int k;
long long ans = 0;
for (k = 1; k < N; k++) ans += combination(N - 1, k) * pow_mod(k, K) % Mod;
printf("%lld\n", ans % Mod);
fflush(stdout);
return 0;
}