标签:std cst target ble mes lan 线性筛 线性 can
欧拉筛O(n)
#include<iostream> #include<cstdio> using namespace std; int n,m,cnt,prime[10000002],v[10000002]; //prime:素数表 v:存某数的最小质因数 int main(){ scanf("%d%d",&n,&m); for(int i=2;i<=n;++i){ if(!v[i]) prime[++cnt]=v[i]=i; for(int j=1;j<=cnt;++j){ if(prime[j]>v[i]||prime[j]>n/i) break; //保证只能被更小的素数筛到 v[prime[j]*i]=prime[j]; } } for(int i=1;i<=m;++i){ int q; scanf("%d",&q); if(v[q]==q) printf("Yes\n"); else printf("No\n"); } return 0; }
标签:std cst target ble mes lan 线性筛 线性 can
原文地址:https://www.cnblogs.com/kafuuchino/p/9606552.html