hdu_5104_素数表的应用

来源:互联网 发布:盐城大数据产业园官网 编辑:程序博客网 时间:2024/06/08 03:30

Primes Problem

Given a number n, please count how many tuple(p1, p2, p3) satisfied that p1<=p2<=p3, p1,p2,p3 are primes and p1 + p2 + p3 = n.
Input
Multiple test cases(less than 100), for each test case, the only line indicates the positive integer n(n≤10000).
Output
For each test case, print the number of ways.
Sample Input
3
9
Sample Output
0
2
Source
BestCoder Round #18

#include<iostream>#include<cstdio>#include<cstring>#include<map>using namespace std;typedef long long ll;int stu[11111]= {0,0,1};int num[11111];int main(){    int i,j,n;    for(i=3; i<=10000; i++)    {        stu[i++]=1;        stu[i]=0;    }    for(i=3; i<=10000; i++)        for(j=i+i; j<=10000; j+=i)            stu[j]=0;    int k=0;    for(i=1; i<=10000; i++)    {        if(stu[i])            num[k++]=i;    }    while(cin>>n)    {        map<int,int> q;        q.clear();        int ans=0;        for(i=0; num[i]<n; i++)        {            for(j=i; num[j]<n-num[i]; j++)            {                if(stu[n-num[i]-num[j]]&&n-num[i]-num[j]>=num[j])                    ans++;            }        }        cout<<ans<<endl;    }    return 0;}/*a s  d   f    a     s      s      */
原创粉丝点击