标签:memset prim c++ scan main oid 检测 mem namespace
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 1e5+10; bool s[maxn]; void is_prime() { memset(s,true,sizeof(s)); s[0] = s[1] = 0; for(int i=2; i*i <= maxn;i++){ if(s[i]){ for(int j=i*i; j <= maxn;j += i) s[j] = 0; } } } int main () { scanf("%d" ,&n); is_prime(); int x; for(int i=1; i <= n;i++){ scanf("%d", &x); if( x <= maxn){ if( s[x] ) printf("Yes\n"); else printf("No\n"); } else{ bool ok = 1; for(int i=2;i*i <= maxn;i++){ if(s[i] && x%i==0){ ok = 0; break; } } if(ok) printf("Yes\n"); else printf("No\n"); } } return 0; }
暴力出奇迹
标签:memset prim c++ scan main oid 检测 mem namespace
原文地址:http://www.cnblogs.com/Draymonder/p/7325971.html