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, ...
随机推荐
- SQL Server 修改AlwaysOn共享网络位置
标签:MSSQL/故障转移 概述 很多人一开始搭建Alwayson的时候对于共享网络位置的选择不是很重视, 导致后面需要去修改这个路径.但是怎样修改这个路径呢?貌似没有给出具体的修改选项,但是还是有地 ...
- Python Web框架(URL/VIEWS/ORM)
一.路由系统URL1.普通URL对应 url(r'^login/',views.login) 2.正则匹配 url(r'^index-(\d+).html',views.index) url(r'^i ...
- Mysql 锁基础
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/53 lock与latch 在数据库中,lock与latch都可以 ...
- WPF单位真的与分辨率无关吗?
转载自http://www.cnblogs.com/helloj2ee/archive/2009/04/21/1440709.htm WPF从发布之日起,一直将"分辨率无关(resoluti ...
- MySQL index 增删改
一.前提信息 1.数据库版本 mysql> select version(),user(); +------------+----------------+ | version() | user ...
- js获取手机屏幕宽度、高度
网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...
- Flask-配置与调试
配置管理 复杂的项目需要配置各种环境.如果设置项很少,可以直接硬编码进来,比如下面的方式: app = Flask(__name__) app.config['DEBUG'] = True app.c ...
- 大数据学习系列之八----- Hadoop、Spark、HBase、Hive搭建环境遇到的错误以及解决方法
前言 在搭建大数据Hadoop相关的环境时候,遇到很多了很多错误.我是个喜欢做笔记的人,这些错误基本都记载,并且将解决办法也写上了.因此写成博客,希望能够帮助那些搭建大数据环境的人解决问题. 说明: ...
- 快速开发基于 HTML5 网络拓扑图应用1
今天开始我们就从最基础解析如何构建 HTML5 Canvas 拓扑图应用,HT 内部封装了一个拓扑图形组件 ht.graph.GraphView(以下简称 GraphView)是 HT 框架中 2D ...
- gitlab勾住rocket chat
出于协作的要求, 需要在把gitlab的push event勾到rocket chat上面, 通知协作的其他人. BUT rocket chat提供的脚本没有具体的文件diff, so, 只好修改一下 ...