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
9
2
//筛素数
#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()的更多相关文章
- hdu 5104 Primes Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5104 Primes Problem Description Given a number n, ple ...
- hdu 5104 Primes Problem(prime 将三重循环化两重)
//宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...
- 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 ...
- hdoj--5104--Primes Problem(素数打表)
Primes Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 5104(数学)
Primes Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)
Primes Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- (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 ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
随机推荐
- iOS中self与_的区别
同时我们发现在我们访问我们声明的变量时,会有self. 和 以"_"开头的访问方式,那么这两种方式到底有什么样的区别呢? 我们来一起看一下: @property (retain, ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)
##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...
- Ubuntu14.04下安装 boost (boost_1.54 最简单的方法)
直接执行命令: sudo apt-get install libboost-dev 测试: 创建一个 boost_test.cpp 文件,写入 #include<iostream> #i ...
- 串口调试者v2.1------开源c#串口调试工具
第一步:上图 第二步:上代码 >>>>>>>>>>>源代码下载<<<<<<<<< ...
- Java NIO (三) 通道(Channel)
通道(Channel):由 java.nio.channels 包定义的,Channel 表示 IO 源与目标打开的连接.Channel 类似于传统的"流",只不过 Channel ...
- MySql Schema 优化
MySQL Schema 优化: 1.保证你的数据库的整洁性. 2.归档老数据 — 删除查询中检索或返回的多余的行 3.在数据上加上索引. 4.不要过度使用索引,评估你的查询. 5 ...
- linux防火墙之 ufw
Usage: ufw COMMAND Commands: enable enables the firewall 开启ufw防火墙 disable disables the firewall 禁用防火 ...
- Java设计模式之(一)------单例模式
1.什么是单例模式? 采取一定的办法保证在整个软件系统中,单例模式确保对于某个类只能存在一个实例.有如下三个特点: ①.单例类只能有一个实例 ②.单例类必须自己创建自己的实例 ③.单例类必须提供外界获 ...
- 解决adb push时出现的"Read-only file system"问题
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 本地Git仓库同步到Bitbucket 远程Git仓库
转载自:http://blog.csdn.net/lue2009/article/details/46553829 本地仓库内容可以和多个远程仓库同步,本地仓库出问题或者远程仓库其中一个有问题,那么剩 ...