当前位置:网站首页>FFT【模板】
FFT【模板】
2022-06-25 06:43:00 【mfy的1号小迷弟】
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=(1<<20)+5;
const double PI=acos(-1);
struct Complex
{
double x,y;
Complex operator+(const Complex &o) const{
return{
x+o.x,y+o.y};}
Complex operator-(const Complex &o) const{
return{
x-o.x,y-o.y};}
Complex operator*(const Complex &o) const{
return{
x*o.x-y*o.y,x*o.y+y*o.x};}
}A[maxn],B[maxn];
int rev[maxn];
int limit=1;
void FFT(Complex *a,int inv){
for(int i=0;i<limit;i++)
if(i<rev[i])swap(a[i],a[rev[i]]);
for(int mid=1;mid<limit;mid<<=1){
Complex Wn=Complex({
cos(PI/mid),inv*sin(PI/mid)});
for(int i=0;i<limit;i+=mid*2){
Complex w=Complex({
1,0});
for(int j=0;j<mid;j++,w=w*Wn){
Complex x=a[i+j],y=w*a[i+j+mid];
a[i+j]=x+y,a[i+j+mid]=x-y;
}
}
}
if(inv==-1) for(int i=0;i<limit;i++) A[i].x/=limit;
}
// --------FFT
int n;
const int Bs=500000;
int vis[maxn];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
int b;
cin>>b;
A[b].x=1;//ax^b, 输入的b是次方,1为系数a
B[Bs-b].x=1;//用Bs-b表示负数
}
int bit=20;
limit=1<<20;//limit要大于最高次数
for(int i=1;i<limit;i++) rev[i]=rev[i>>1]>>1|(i&1)<<(bit-1);
FFT(A,1),FFT(B,1);
for(int i=0;i<limit;i++) A[i]=A[i]*B[i];
FFT(A,-1);
for(int i=0;i<=Bs;i++) vis[i]=int(A[i+Bs].x+0.5);//表示系数,因为是减法,加过Bs,大于Bs的符合要求,进行判断是否存在改次方
for(int i=n;;i++)
{
bool ok=1;
for(int j=i;j<=Bs;j+=i)
if(vis[j]) {
ok=0;break;}
if(ok) return cout<<i<<'\n',0;
}
return 0;
}
边栏推荐
- VSCode很好,但我以后不会再用了
- Linux上oracle和mysql的启动,关闭,重启
- One "stone" and two "birds", PCA can effectively improve the dilemma of missing some ground points under the airborne lidar forest
- [single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
- Kinsing双平台挖矿家族病毒分析
- Ubuntu18下登录mysql 5.7设置root密码
- [daily training] 207 Class Schedule Card
- 50. pow (x, n) - fast power
- NSIS silent installation vs2013 runtime
- Different paths ii[dynamic planning improvement for DFS]
猜你喜欢

Tips on how to design soft and hard composite boards ~ 22021/11/22

Vscode is good, but I won't use it again

Terms and concepts related to authority and authentication system

Find out what informatization is, and let enterprises embark on the right path of transformation and upgrading

ts环境搭建

Hisilicon 3559 sample parsing: Vio

Five causes of PCB board deformation and six solutions 2021-10-08

Invalid Navicat scheduled task

搞清信息化是什么,让企业转型升级走上正确的道路

NPM install reports an error: gyp err! configure error
随机推荐
2160. 拆分数位后四位数字的最小和
力扣76题,最小覆盖字串
Import data into Matlab
【深度学习 轻量型backbone】2022 EdgeViTs CVPR
[single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
WinForm implementation window is always at the top level
1464. 数组中两元素的最大乘积
What are the benefits of reserving process edges for PCB production? 2021-10-25
【日常训练】207. 课程表
Mining microbial dark matter -- a new idea
基于STM32MP157调试MIPI-DSI屏幕
C# 读取web上的xml
搞清信息化是什么,让企业转型升级走上正确的道路
VOCALOID笔记
Storage of Galileo broadcast ephemeris in rtklib-b33
Function template_ Class template
【Unexpected token o in JSON at position 1出错原因及解决方法】
C control refresh
Anaconda based module installation and precautions
Fairmot yolov5s to onnx