【小猪佩奇学数学 题解】一定要写一些东西才看起来可爱嘛
teylnol_evteyl · · 题解
计算:
其中
把
先看
由于
所以有
再看另一部分
可以发现
所以只需要计算这个多项式时,把次数取模即可。
FFT 有一个性质是:当多项式乘出来的长度大于进行 FFT 的长度
由于这一题
将两部分的结果相减,除以
时间复杂度
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1 << 20 | 5, P = 998244353, G = 3;
int n, p, k;
LL a[N];
inline LL ksm(LL a, LL n)
{
LL res = 1;
while(n)
{
if(n & 1) res = res * a % P;
a = a * a % P;
n >>= 1;
}
return res;
}
inline void NTT(LL a[], int n, int ty)
{
for(int i = 0, j = 0; i < n; i ++ )
{
if(i < j) a[i] ^= a[j] ^= a[i] ^= a[j];
for(int k = (n >> 1); (j ^= k) < k; k >>= 1) ;
}
static LL w[N];
w[0] = 1;
for(int i = 1; i < n; i <<= 1)
{
LL wi = ksm(G, P - 1 + ty * (P - 1) / (i << 1));
for(int j = i - 2; j >= 0; j -= 2)
{
w[j] = w[j >> 1];
w[j | 1] = w[j] * wi % P;
}
for(int j = 0; j < n; j += (i << 1))
{
for(int k = j; k < j + i; k ++ )
{
LL t0 = a[k], t1 = a[k + i] * w[k - j] % P;
(a[k] = t0 + t1) >= P && (a[k] -= P), (a[k + i] = t0 - t1 + P) >= P && (a[k + i] -= P);
}
}
}
if(ty == -1)
{
LL inv = ksm(n, P - 2);
for(int i = 0; i < n; i ++ ) a[i] = a[i] * inv % P;
}
}
int main()
{
scanf("%d%d%d", &n, &p, &k);
LL res = ksm(p + 1, n - 1) * n % P * p % P;
a[0] = 1, a[1] = p;
NTT(a, k, 1);
for(int i = 0; i < k; i ++ ) a[i] = ksm(a[i], n);
NTT(a, k, -1);
for(int i = 1; i < k; i ++ ) res = (res + (P - i) * a[i]) % P;
printf("%lld\n", res * ksm(k, P - 2) % P);
return 0;
}