HDU2161
解题思路:判断素数模板题。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 16005; 6 int vis[maxn]; 7 8 void Init() 9 { 10 memset(vis, 0, sizeof(vis)); 11 vis[1] = 1; 12 for(int i = 2; i <= maxn; i++) 13 { 14 for(int j = i+i; j <= maxn; j +=i) 15 vis[j] = 1; 16 } 17 return ; 18 } 19 int main() 20 { 21 Init(); 22 int n, kase = 1; 23 while(~scanf("%d", &n)) 24 { 25 if(n <= 0) break; 26 if(n == 1 || n == 2) 27 { 28 printf("%d: no\n", kase++); 29 continue; 30 } 31 if(!vis[n]) printf("%d: yes\n", kase++); 32 else printf("%d: no\n", kase++); 33 } 34 return 0; 35 }