数学推导题,NTT,快速数论变换,Wannafly-导数卷积
导数卷积
题目描述
题解
参考了一下标程的推导过程,因为这个推导对我这种数学弱渣真的有点难鸭.
[1]的次导函数:
[2]的次导函数:
对于积式结果中,次数为的项前的系数应该是:
令
换种写法:
对所有的积式求和得到:
在上个式子中必须要满足, 即, ,不然将变成,不过对答案没有影响.
的取值范围是,也就是.
因此上个式子就是,
对后面的部分直接套用来求就可以了.
代码
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define rep(i,a,b) for(int i = a;i <= b;++i)
typedef long long LL;
const int N = 1 << 20;
const int P = 998244353;
const int G = 3;
const int NUM = 20;
LL wn[NUM];
LL a[N], b[N];
LL quick_mod(LL a, LL b, LL m)
{
LL ans = 1;
a %= m;
while(b)
{
if(b & 1)
{
ans = ans * a % m;
b--;
}
b >>= 1;
a = a * a % m;
}
return ans;
}
void GetWn()
{
for(int i = 0; i < NUM; i++)
{
int t = 1 << i;
wn[i] = quick_mod(G, (P - 1) / t, P);
}
}
void Rader(LL a[], int len)
{
int j = len >> 1;
for(int i = 1; i < len - 1; i++)
{
if(i < j) swap(a[i], a[j]);
int k = len >> 1;
while(j >= k)
{
j -= k;
k >>= 1;
}
if(j < k) j += k;
}
}
void NTT(LL a[], int len, int on)
{
Rader(a, len);
int id = 0;
for(int h = 2; h <= len; h <<= 1)
{
id++;
for(int j = 0; j < len; j += h)
{
LL w = 1;
for(int k = j; k < j + h / 2; k++)
{
LL u = a[k] % P;
LL t = w * a[k + h / 2] % P;
a[k] = (u + t) % P;
a[k + h / 2] = (u - t + P) % P;
w = w * wn[id] % P;
}
}
}
if(on == -1)
{
for(int i = 1; i < len / 2; i++)
swap(a[i], a[len - i]);
LL inv = quick_mod(len, P - 2, P);
for(int i = 0; i < len; i++)
a[i] = a[i] * inv % P;
}
}
void Conv(LL a[], LL b[], int n)
{
NTT(a, n, 1);
NTT(b, n, 1);
for(int i = 0; i < n; i++)
a[i] = a[i] * b[i] % P;
NTT(a, n, -1);
}
int n;
LL Fac[N],iFac[N];
int main()
{
GetWn();
Fac[0] = 1;
rep(i,1,N-1)
Fac[i] = Fac[i-1] * i % P;
rep(i,0,N-1)
iFac[i] = quick_mod(Fac[i],P-2,P);
ios::sync_with_stdio(false);
cin >> n;
rep(i,0,n-1) {
std::cin >> a[i];
a[i] = b[i] = a[i] * Fac[i] % P;
}
int len = 1;
while(len < n) len <<= 1;
len <<= 1;
Conv(a,b,len);
rep(i,0,n-1) {
std::cout << a[n-1+i] * quick_mod(2,i,P) % P * iFac[i] % P << " ";
}
return 0;
}