POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水)
代码总览
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#define nmax 10005
using namespace std;
int prime[nmax],n;
vector<int> vprime;
void init()
{
memset(prime,0,sizeof(prime));
int up = sqrt(nmax)+1;
for(int i = 2;i<=up;++i){
if(prime[i] == 0)
for(int j = 2;i*j<=nmax;++j){
prime[i*j] = 1;//not prime
}
}
for(int i = 2; i<=nmax;++i){
if(prime[i] == 0){
//printf("%d\n",i);
vprime.push_back(i);
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
init();
while(scanf("%d",&n) !=EOF && n){
int ans = 0;
int total = 0;
for(int i = 0;i<vprime.size();++i){
total = vprime[i];
if(vprime[i] == n){
ans++;
break;
}else if(vprime[i]>n) break;
for(int k = i+1;k<vprime.size();++k){
total += vprime[k];
if(total == n) ans++;
else if(total>n) break;
}
}
printf("%d\n",ans);
}
return 0;
}
POJ.2739 Sum of Consecutive Prime Numbers(水)的更多相关文章
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- poj 2739 Sum of Consecutive Prime Numbers 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
随机推荐
- textview的阴影线
android:shadowColor="#000000" android:shadowDx="1" android:shadowDy="1" ...
- 怎样用Eclipse将Java源代码生成可执行文件[转]
eclipse将java源代码生成jar可执行文件 用eclipse做了一个web项目的自动化测试,自己用的时候倒是很方便,打开eclipse直接运行即可,但是分享给其他小伙伴用的时候就不太方便,希望 ...
- 了解Python控制流语句——while 语句
while 语句 Python 中 while 语句能够让你在条件为真的前提下重复执行某块语句. while 语句是 循环(Looping) 语句的一种.while 语句同样可以拥有 else 子句作 ...
- git push origin master 错误解决办法
一.错误代码如下: error: failed to push some refs to 'https://github.com/wbingithub/drag.git' 二.在网上搜了一下,如下写就 ...
- jQuery实现checkbox(复选框)选中、全选反选代码
谁都知道 在html 如果一个复选框被选中 是 checked="checked". 但是我们如果用jquery alert($("#id").attr(&qu ...
- Simple Expression
Description You probably know that Alex is a very serious mathematician and he likes to solve seriou ...
- c# dll问题
问题描述: dll完全拷贝另一个程序,可是报缺少引用程序集之类的错误. 解决办法: 有可能是.net版本造成的错误.一般常见在3.5升到4之后,存在很多容差.
- [离散化]人潮最多的時段( Interval Partitioning Problem )
範例:人潮最多的時段( Interval Partitioning Problem ) 一群訪客參加宴會,我們詢問到每一位訪客的進場時刻與出場時刻,請問宴會現場擠進最多人的時段. 換個角度想,想像會場 ...
- 移动端的picker参考vux
参考vux移动端的ui组件,做了一个picker,测试在微信,uc主流浏览器能够正常工作.而在华为浏览器根本不能使用.而测试了vux的原有picker组件,发现在华为自带浏览器中,效果依然能够实现. ...
- CEntOS6.5从启动界面直接进入命令行界面
ctrl + alt + F1 ctrl + alt + F2 ctrl + alt + F3 ctrl + alt + F4 ctrl + alt + F5 ctrl + alt + F6 同时按下 ...