#### 个数两个相减（相加）先序知识

##### 具体问题讲解

###### Slove

```#include <cstdio>
#include <complex>
#include <cmath>
using namespace std;

int n,m;
typedef complex<double> CP;
const int lim = 1<<21;
const double Pi = acos(-1);
const int P = 500001;
CP a[lim],b[lim];
bool vis[lim];

void FFT(CP *x,int lim,int inv) // 板子而已
{
int bit = 1,m;
CP stand,now,temp;
while((1<<bit) < lim) ++bit;
for (int i = 0; i < lim; ++i)
{
m = 0;
for (int j = 0; j < bit; ++j)
if(i & (1<<j)) m |= (1<<(bit-j-1));
if(i < m) swap(x[m],x[i]);
}
for (int len = 2; len <= lim; len <<= 1)
{
m = len >> 1;
stand = CP(cos(2*Pi/len),inv*sin(2*Pi/len));
for (CP *p = x; p != x+lim; p += len)
{
now = CP(1,0);
for (int i = 0; i < m; ++i,now*=stand)
{
temp = now * p[i+m];
p[i+m] = p[i] - temp;
p[i] = p[i] + temp;
}
}
}
if(inv == -1)
for (int i = 0; i < lim; ++i)
x[i].real(x[i].real()/lim);
}

bool check(int x)
{
for (int i = x; i <= P; i += x)
{
if (vis[i] == 1) return 0;
}
return 1;
}

int main()
{
int x;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%d",&x);
a[x].real(1);
b[P - x].real(1); // 负数做偏移
}
int num = 1 << 20;
FFT(a,num,1);
FFT(b,num,1);
for (int i = 0; i < num; ++i)
a[i] *= b[i];
FFT(a,num,-1);
for (int i = 0; i <= num; ++i)
{
x = (int)floor(a[i].real()+0.5);
if (x > 0) vis[abs(i - P)] = 1;
}
for (int  i = n; i < P+1; ++i)
if (check(i))
{
printf ("%d\n",i);
break;
}
return 0;
}```