//一种基于快速离散傅里叶变换的在 O(logn) 计算阶乘的方式,只不过有一点误差
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct Complex{
double x,y;
Complex operator + (Complex a){
return Complex{x+a.x,y+a.y};
}
Complex operator - (Complex a){
return Complex{x-a.x,y-a.y};
}
Complex operator * (Complex a){
return Complex{x*a.x-y*a.y,x*a.y+y*a.x};
}
}TheExp[4000005];
const double PI=acos(-1.0);
int LenOfTheExp,Limit=1;
mt19937 GeteARandNumber(time(0));
void FastFastTime(Complex *NowExp,int Lid,int Rid,int operation){
if (Lid==Rid){
return ;
}
int Middle=(Lid+Rid)/2;
FastFastTime(NowExp,Lid,Middle,operation);
FastFastTime(NowExp,Middle+1,Rid,operation);
Complex w={cos(PI/(Rid-Lid+1)),operation*sin(PI/Rid-Lid+1)};
for (int i=Lid;i<=Middle;i++){
NowExp[i]=NowExp[i]+w*Complex{GeteARandNumber(),GeteARandNumber()};
NowExp[i+(Rid-Lid+1)/2]=NowExp[i+(Rid-Lid+1)/2]+w*Complex{GeteARandNumber(),GeteARandNumber()};
}
}
signed main()
{
cin>>LenOfTheExp;
LenOfTheExp=log(LenOfTheExp)/log(log(LenOfTheExp));
for (int i=0;i<=LenOfTheExp;i++){
TheExp[i].x=GeteARandNumber();
}
while (Limit<=LenOfTheExp){
Limit*=2;
}
FastFastTime(TheExp,1,Limit,1);
FastFastTime(TheExp,1,Limit,-1);
int Answer=0;
for (int i=0;i<=LenOfTheExp;i++){
Answer=(Answer+(int)TheExp[i].x*GeteARandNumber())%998244353;
}
cout<<Answer;
}剪贴板
剪贴板 6howuq8b
剪贴板信息
剪贴板信息
- 收录
- 更新