题目链接: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, 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
 
题意:输入一个数字n,找出三个数字p1,p2,p3,满足p1<=p2<=p3并且p1+p2+p3=n
 //筛素数
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
bool pri[N];
int prime[N];
int cnt;
void init()
{
cnt = ;
pri[] = pri[] = ;
for(int i = ; i < N; i++)
{
if(!pri[i]){
prime[cnt++] = i;
for(int j = i+i; j < N; j+=i)
{
pri[j] = ;
}
}
}
return;
}
int main()
{
int n;
init();
while(~scanf("%d",&n))
{
int ans = ; //printf("%d\n",cnt);
for(int i = ; i < cnt; i++)
{
if(*prime[i]>n) break;
for(int j = i; j < cnt; j++)
{
if(prime[i]+*prime[j]>n) break;
//for(int k = j; k < cnt; k++)
//{
// if(prime[i]+prime[j]+prime[k]==n) ans++;// printf("%d %d %d\n",prime[i],prime[j],prime[k]);printf("%d %d %d\n",i,j,k);}
// }
if(!pri[n-prime[i]-prime[j]]) ans++;
}
}
printf("%d\n",ans);
}
return ;
}

hdu_5104 Primes Problem()的更多相关文章

  1. hdu 5104 Primes Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...

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

    //宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...

  3. Project Euler Problem 10

    Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...

  4. hdoj--5104--Primes Problem(素数打表)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. hdu 5104(数学)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)

    Primes Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  8. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  9. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

随机推荐

  1. iOS中self与_的区别

    同时我们发现在我们访问我们声明的变量时,会有self. 和 以"_"开头的访问方式,那么这两种方式到底有什么样的区别呢? 我们来一起看一下: @property (retain, ...

  2. 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)

    ##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...

  3. Ubuntu14.04下安装 boost (boost_1.54 最简单的方法)

    直接执行命令: sudo apt-get  install libboost-dev 测试: 创建一个 boost_test.cpp 文件,写入 #include<iostream> #i ...

  4. 串口调试者v2.1------开源c#串口调试工具

    第一步:上图 第二步:上代码 >>>>>>>>>>>源代码下载<<<<<<<<< ...

  5. Java NIO (三) 通道(Channel)

    通道(Channel):由 java.nio.channels 包定义的,Channel 表示 IO 源与目标打开的连接.Channel 类似于传统的"流",只不过 Channel ...

  6. MySql Schema 优化

    MySQL Schema 优化:   1.保证你的数据库的整洁性.   2.归档老数据 — 删除查询中检索或返回的多余的行   3.在数据上加上索引.   4.不要过度使用索引,评估你的查询.   5 ...

  7. linux防火墙之 ufw

    Usage: ufw COMMAND Commands: enable enables the firewall 开启ufw防火墙 disable disables the firewall 禁用防火 ...

  8. Java设计模式之(一)------单例模式

    1.什么是单例模式? 采取一定的办法保证在整个软件系统中,单例模式确保对于某个类只能存在一个实例.有如下三个特点: ①.单例类只能有一个实例 ②.单例类必须自己创建自己的实例 ③.单例类必须提供外界获 ...

  9. 解决adb push时出现的"Read-only file system"问题

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  10. 本地Git仓库同步到Bitbucket 远程Git仓库

    转载自:http://blog.csdn.net/lue2009/article/details/46553829 本地仓库内容可以和多个远程仓库同步,本地仓库出问题或者远程仓库其中一个有问题,那么剩 ...