当前位置:网站首页>FFT [template]
FFT [template]
2022-06-25 08:05:00 【Mfy's little brother 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, Input b Is power ,1 Is the coefficient a
B[Bs-b].x=1;// use Bs-b A negative number
}
int bit=20;
limit=1<<20;//limit Must be greater than the maximum number of times
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);// The coefficient , Because it's subtraction , Added Bs, Greater than Bs And meet the requirements , Determine whether there is a modified power
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;
}
边栏推荐
猜你喜欢
Import data into Matlab
Debugging mipi-dsi screen based on stm32mp157
【论文学习】《VQMIVC》
c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例
使用Adobe Acrobat Pro调整PDF页面为统一大小
socket问题记录
To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
Looking for b-end product manager after years? I almost ruined myself
How much do you know about electronic components on PCB?
Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries
随机推荐
bat启动.NET Core
现在通过开户经理发的开户链接股票开户安全吗?
MySQL简单权限管理
Solving some interesting problems with recurrence of function
【补题】2021牛客暑期多校训练营6-n
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
网络模型——OSI模型与TCP/IP模型
黑点==白点(MST)
【Unexpected token o in JSON at position 1出错原因及解决方法】
电子学:第010课——实验 9:时间与电容器
电子学:第008课——实验 6:非常简单的开关
27. remove elements
初体验完全托管型图数据库 Amazon Neptune
Luogu p5994 [pa2014]kuglarz (XOR thinking +mst)
用函数的递归来解决几道有趣的题
Electronics: Lesson 012 - Experiment 13: barbecue LED
Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries
417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)
Looking for b-end product manager after years? I almost ruined myself
Invalid Navicat scheduled task