Codeforces 286E

时间:2023-03-08 21:07:20

Codeforces 286E

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
using namespace std; const int maxn=int(1e6)+;
const double eps=0.5;
const double PI=acos(-); struct Complex
{
double real, imag; Complex(double _x=, double _y=):real(_x), imag(_y) {} Complex operator + (Complex b)
{
return Complex(real+b.real, imag+b.imag);
} Complex operator - (Complex b)
{
return Complex(real-b.real, imag-b.imag);
} Complex operator * (Complex b)
{
return Complex(real*b.real-imag*b.imag, real*b.imag+b.real*imag);
}
}; int n, m;
int lg, wide;
bool vis[maxn];
int ans[maxn], rev[maxn*];
Complex a[maxn*]; void init()
{
scanf("%d%d", &n, &m);
for (int i=; i<=n; ++i)
{
int num;
scanf("%d", &num);
vis[num]=true;
a[num].real=;
}
}
void init_order()
{
for (int i=; i<wide; ++i)
for (int j=; j<lg; ++j)
rev[i]=(rev[i]<<) | (i>>j & );
}
void FFT(int type)
{
for (int i=; i<wide; ++i)
if (rev[i]>i) swap(a[i], a[rev[i]]); for (int i=; i<=wide; i<<=)
for (int j=; j<wide; j+=i)
{
Complex w(cos(PI*/i), sin(PI*/i*(-type)));
Complex wn(, );
for (int k=; k<i>>; ++k, wn=wn*w)
{
Complex tmp=a[j+k];
a[j+k]=tmp+wn*a[j+k+(i>>)];
a[j+k+(i>>)]=tmp-wn*a[j+k+(i>>)];
}
}
}
void solve()
{
lg=;
while (<<lg<m*) ++lg;
wide=<<lg;
init_order();
FFT();
for (int i=; i<wide; ++i) a[i]=a[i]*a[i];
FFT(-);
for (int i=; i<wide; ++i) a[i].real/=wide;
/*
for (int i=0; i<wide; ++i)
printf("%d ", int(a[i].real+0.5));
*/
bool flag=true;
for (int i=; i<=m; ++i)
if (a[i].real>eps && !vis[i])
{
flag=false;
break;
}
if (!flag) printf("NO\n");
else
{
printf("YES\n");
for (int i=; i<=m; ++i)
if (vis[i] && a[i].real<eps)
ans[++ans[]]=i;
printf("%d\n", ans[]);
for (int i=; i<=ans[]; ++i)
printf("%d ", ans[i]);
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
init();
solve();
return ;
}