HDU 5104 Primes Problem(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104

Problem Description

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 <cstdio>
#include <iostream>
#include <cstring>
int p[10017];
void init()
{
    memset(p,0,sizeof(p));
    for(int i = 2; i <= 10000; i++)
    {
        if(p[i] == 0)
        {
            for(int j = i*i; j <= 10000; j+=i)
            {
                p[j] = 1;
            }
        }
    }
}
int main()
{
    int a[10017];
    int n;
    init();
    while(~scanf("%d",&n))
    {
        int cont = 0;
        for(int i = 2; i <= n; i++)
        {
            if(p[i] == 0)
                for(int j = i; j <= n; j++)
                {
                    if(p[j] == 0 && p[n-i-j] == 0)
                        if(n-i-j>=i && n-i-j>=j)
                        {
                            cont++;
                        }
                }
        }
        printf("%d\n",cont);
    }
    return 0;
}
时间: 2024-08-10 17:01:29

HDU 5104 Primes Problem(数学)的相关文章

hdu 5104 Primes Problem (素数 打表 水)

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)

hdu 5104 Primes Problem (素数+递推)

Problem Description 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 int

hdu 5104 Primes Problem(prime 将三重循环化两重)

//宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using namespace std; int prime[1000],num[10005]; int Cout; void initPrime() { for(int i=2;i<=10000;i++) num[i]=1; for(int i=2;i<=10000;i++) { if(num[i]) { for(

hdu 5105 Math Problem(数学)

题目链接:hdu 5105 Math Problem 题目大意:给定a,b,c,d,l,r,表示有一个函数f(x)=|a?x3+b?x2+c?x+d|(L≤x≤R),求函数最大值. 解题思路:考虑极点即可,将函数求导后得到f′(x)=0的x,即为极值点.在极值点处函数的单调性会发生变化,所以最大值一定就在区间边界和极值点上.注意a=0,b=0的情况,以及极值点不在区间上. #include <cstdio> #include <cstring> #include <cmath

HDU 5105 Math Problem --数学,求导

官方题解: f(x)=|a∗x3+b∗x2+c∗x+d|, 求最大值.令g(x)=a∗x3+b∗x2+c∗x+d,f(x)的最大值即为g(x)的正最大值,或者是负最小值.a!=0时, g′(x)=3∗a∗x2+2∗b∗x+c 求出g′(x)的根(若存在,x1,x2,由导数的性质知零点处有极值.ans=max(f(xi)|L≤xi≤R).然后考虑两个端点的特殊性有ans=max(ans,f(L),f(R)). 当时 x = -c/(2*b) 写成 x = -c/2*b 了,然后过pretest了.

hdu 5104(数学)

Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2841    Accepted Submission(s): 1276 Problem Description Given a number n, please count how many tuple(p1, p2, p3) satisfied that p

hdu_5104 Primes Problem()

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104 rimes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2844    Accepted Submission(s): 1277 Problem Description Given a number n, pleas

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

HDU 1018 Big Number 数学题解

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of