3 9
0 2
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int main() { int n, prime[2000], pnum=0, isprime[10005]; memset(isprime, 0, sizeof(isprime)); for(int i=2; i<=10000; i++) { if(!isprime[i]) { prime[pnum++] = i; for(int j = i<<1; j<=10000; j+=i) isprime[j] = 1; } } /*for(int i=0; i<pnum; i++) { printf("%d ", prime[i]); }*/ while(scanf("%d", &n)!=EOF) { int i, j, ans=0; for(i = 0; prime[i]<=n; i++) { for(j = i; prime[j]<=n; j++) { int t = n - prime[i] - prime[j]; if(t>=prime[j] && isprime[t]==0)ans++; } } printf("%d\n", ans); } return 0; }
HDU-5104-Primes Problem (BestCoder Round #18!!)
原文地址:http://blog.csdn.net/u014355480/article/details/41393471