线性求素数+莫比乌斯函数+欧拉函数模板
RT,只是想存个模板而已。
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int prime[10000005],ol[10000005],mul[10000005];
bool vis[10000005];
int cnt;
void Prime(int n)
{
vis[1]=1;ol[1]=mul[1]=1;
for(int i=2;i<=n;i++)
{
if(!vis[i])
prime[++cnt]=i,ol[i]=i-1,mul[i]=-1;
for(int j=1;j<=cnt&&i*prime[j]<=n;j++)
{
vis[i*prime[j]]=1;
if(!(i%prime[j])) {ol[i*prime[j]]=ol[i]*prime[j];break;}
else ol[i*prime[j]]=ol[i]*(prime[j]-1),mul[i*pri[j]]=-mul[i];
}
}
}
int main()
{
int i,j,k,n,m;
cin>>k>>j;
Prime(k);
for(i=1;i<=j;i++)
{
cin>>n;
if(vis[n]==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}