1 2 3 4 5 17 0
1: no 2: no 3: yes 4: no 5: yes 6: yes
AC代码:
#include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define INF 0x7fffffff using namespace std; const int maxn = 20000; int prime[20000]; void init() { prime[1] = 2; for(int i = 2; i < maxn; i ++) if(prime[i] == 0) { prime[i] = 1; for(int j = i * 2; j < maxn; j += i) { prime[j] = 2; } } prime[2] = 2; } int main() { init(); int cas = 1; int a; while(scanf("%d", &a) != EOF) { if(a == 0) break; if(prime[a] == 1) { printf("%d: yes\n", cas ++); } else if(prime[a] == 2) { printf("%d: no\n", cas ++); } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u014355480/article/details/47083673