线性么,时间复杂度O(n) 蛮好,蛮经典 洛谷模版 其实临场应该自己会打
#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<cstring>#define Ll long longusing namespace std;int a[500],zhi[10000001];bool b[10000001],ans[10000001];int n,m,x;void make(){ int l=2; int k,s; while(l<10000000){ zhi[++m]=l; ans[l]=1; k=s=l; while(s<10000000){ b[s]=1; s+=k; } while(l<10000000&&b[l])l++; }}int main(){ make(); cin>>n>>n; while(n--){ cin>>x; if(ans[x])cout<<"Yes/n";else cout<<"No/n"; }}新闻热点
疑难解答