[hdu5104]枚举

http://acm.hdu.edu.cn/showproblem.php?pid=5104

求出前10000的素数,按大小顺序枚举2个得出第3个,判断一下是否有序,更新答案。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <map>
 7 #include <vector>
 8 #include <stack>
 9 #include <string>
10 #include <ctime>
11 #include <queue>
12 #define mem0(a) memset(a, 0, sizeof(a))
13 #define mem(a, b) memset(a, b, sizeof(a))
14 #define lson l, m, rt << 1
15 #define rson m + 1, r, rt << 1 | 1
16 #define eps 0.0000001
17 #define lowbit(x) ((x) & -(x))
18 #define memc(a, b) memcpy(a, b, sizeof(b))
19 #define x_x(a) ((a) * (a))
20 #define LL long long
21 #define DB double
22 #define pi 3.14159265359
23 #define MD 10000007
24 #define INF
25 #define max(a, b) ((a) > (b)? (a) : (b))
26 using namespace std;
27 int prime[2200], flag[12000];
28 void init()
29 {
30         int cnt = 0;
31         flag[1] = 1;
32         for(int i = 2; i <= 10000; i++) {
33                 if(!flag[i]) {
34                         prime[++cnt] = i;
35                         for(int j = i * i; j <= 10000; j += i) {
36                                 flag[j] = 1;
37                         }
38                 }
39         }
40 }
41 int main()
42 {
43         //freopen("input.txt", "r", stdin);
44         init();
45         int n;
46         while(~scanf("%d", &n)) {
47                 int ans = 0;
48                 for(int i = 1; prime[i] < n; i++) {
49                         for(int j = i; prime[i] + prime[j] < n; j++) {
50                                 int tmp = n - prime[i] - prime[j];
51                                 if( tmp >= prime[j] && !flag[tmp]) {
52                                         ans++;
53                                 }
54                         }
55                 }
56                 printf("%d\n", ans);
57         }
58         return 0;
59 }
View Code

 

posted @ 2014-11-21 18:19  jklongint  阅读(97)  评论(0编辑  收藏  举报