题目链接: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 ;
}

最新文章

  1. ORA-12520:TNS:监听程序无法为请求的服务器类型找到可用的处理程序
  2. [转]Spring3 MVC + jQuery easyUI 做的ajax版本用户管理
  3. 八款你不得不知的开源前端JS框架
  4. SharePoint 2010中使用SPListItemCollectionPosition更快的结果
  5. discuz X3.1的门户文章实现伪静态,利于搜索引擎收录url的地址修改
  6. python apschedule安装使用与源码分析
  7. git使用过程中遇到的问题及处理方法
  8. linux shell 基本规范
  9. parted分区和挂载及非交互式操作
  10. spring javaconfig druidsource
  11. (转)用JS获取地址栏参数的方法(超级简单)
  12. build.gradle
  13. 一些安全相关的HTTP header
  14. Codeforces Round #493 (Div. 2)
  15. webstorm我用到的快捷键【不断更新】
  16. 涨知识:equals 和 == 你真的了解吗?
  17. 使用CSS进行定位
  18. 生成activiti需要的25张系统表
  19. 「Python」pandas入门教程
  20. Linux汇编教程02:编写第一个汇编程序

热门文章

  1. Python 项目实践二(下载数据)第三篇
  2. 最长回文子序列(LPS)
  3. IDA分析脱壳后丢失导入表的PE
  4. vue2 vue-rout
  5. 安装lamp代码
  6. 二:mysql安装配置、主从复制配置详解
  7. Java的注释和Javadoc在eclipse生成的方法 – Break易站
  8. js 数组API之filter的用法
  9. mysql优化-》查询缓存
  10. 自学Aruba1.2-WLAN一些基本常识