hdu_5104_素数表的应用

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
      */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值