标签:des style blog io color ar os sp java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12 Accepted Submission(s): 11
#include <string> #include <iostream> #include <cstdio> #include <math.h> #include <cstring> #include <algorithm> #include <queue> using namespace std; int f[10001]; void sushu() { int i, j; memset(f, 0, sizeof(f)); f[1]=1; i=2; while(i<=200) { for(j=i*2; j<=10000; j+=i) { f[j]=1; } i++; while(f[i]==1) { i++; } } } int s[10000], e; int main() { int n; int i, j, k; int cnt; sushu(); e=0; for(i=2; i<=10000; i++) { if(f[i]==0) { s[e++]=i; } } while(scanf("%d", &n)!=EOF) { if(n<6) { cout<<‘0‘<<endl; continue; } cnt=0; for(i=0; i<=n; i++) { for(j=i; j<=n; j++) { for(k=j; k<=n; k++) { if((s[i]+s[j]+s[k])==n) { cnt++; } } } } cout<<cnt<<endl; } return 0; }
Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)
标签:des style blog io color ar os sp java
原文地址:http://www.cnblogs.com/yspworld/p/4100215.html