题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104
题面:
3 9
0 2
解题:
唉,说好不刷水题的了,又刷,真是不好...
代码:
#include <iostream> #include <cmath> using namespace std; int store_prime[10000],cnt=0; bool is_prime(int x) { if(x==2)return true; int up_limit=sqrt(1.0*x); for(int i=2;i<=up_limit;i++) { if(x%i==0)return false; } return true; } int main() { for(int i=2;i<=10000;i++) { if(is_prime(i)) { store_prime[cnt++]=i; } } int tmp,sum,n,ans; while(cin>>n) { ans=0; for(int i=0;i<cnt;i++) { for(int j=i;j<cnt;j++) { tmp=n-store_prime[i]-store_prime[j]; if(tmp>=store_prime[j]&&is_prime(tmp)) ans++; } } cout<<ans<<endl; } return 0; }