标签:
http://acm.hdu.edu.cn/showproblem.php?pid=5104
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int isp[10000+100]; int prime[10000]; int coun; bool isprime(int x) { int i,j; for(i=2;i<=sqrt(x);i++) { if(x%i==0) return false; } return true; } void fun() { int i,j; for(i=2;i<=10000;i++) { if(isp[i]!=0) continue; if(isprime(i)) { isp[i]=1; prime[coun++]=i; } j=i; while(j+i<=10000) { j+=i; isp[j]=2; } } } int main() { //freopen("output.txt","w",stdout); int ans; int i,j,k,n; memset(isp,0,sizeof(isp)); coun=0; fun(); //printf("%d...\n",coun); while(scanf("%d",&n)!=EOF) { int ans=0; for(i=0;i<coun;i++) { if(prime[i]>n/3) break; for(j=i;prime[j]<=(n-prime[i])/2;j++) { k=n-prime[i]-prime[j]; if(isp[k]==1) ans++; } } printf("%d\n",ans); //n++; } return 0; }
hdu 5104 Primes Problem (素数 打表 水)
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4231778.html