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(水)的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  4. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

  5. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895 ...

  6. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  7. poj 2739 Sum of Consecutive Prime Numbers 小结

     Description Some positive integers can be represented by a sum of one or more consecutive prime num ...

  8. poj 2739 Sum of Consecutive Prime Numbers 尺取法

    Time Limit: 1000MS   Memory Limit: 65536K Description Some positive integers can be represented by a ...

  9. poj 2739 Sum of Consecutive Prime Numbers 解题报告

    题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...

随机推荐

  1. textview的阴影线

    android:shadowColor="#000000" android:shadowDx="1" android:shadowDy="1" ...

  2. 怎样用Eclipse将Java源代码生成可执行文件[转]

    eclipse将java源代码生成jar可执行文件 用eclipse做了一个web项目的自动化测试,自己用的时候倒是很方便,打开eclipse直接运行即可,但是分享给其他小伙伴用的时候就不太方便,希望 ...

  3. 了解Python控制流语句——while 语句

    while 语句 Python 中 while 语句能够让你在条件为真的前提下重复执行某块语句. while 语句是 循环(Looping) 语句的一种.while 语句同样可以拥有 else 子句作 ...

  4. git push origin master 错误解决办法

    一.错误代码如下: error: failed to push some refs to 'https://github.com/wbingithub/drag.git' 二.在网上搜了一下,如下写就 ...

  5. jQuery实现checkbox(复选框)选中、全选反选代码

    谁都知道 在html 如果一个复选框被选中 是 checked="checked". 但是我们如果用jquery alert($("#id").attr(&qu ...

  6. Simple Expression

    Description You probably know that Alex is a very serious mathematician and he likes to solve seriou ...

  7. c# dll问题

    问题描述: dll完全拷贝另一个程序,可是报缺少引用程序集之类的错误. 解决办法: 有可能是.net版本造成的错误.一般常见在3.5升到4之后,存在很多容差.

  8. [离散化]人潮最多的時段( Interval Partitioning Problem )

    範例:人潮最多的時段( Interval Partitioning Problem ) 一群訪客參加宴會,我們詢問到每一位訪客的進場時刻與出場時刻,請問宴會現場擠進最多人的時段. 換個角度想,想像會場 ...

  9. 移动端的picker参考vux

    参考vux移动端的ui组件,做了一个picker,测试在微信,uc主流浏览器能够正常工作.而在华为浏览器根本不能使用.而测试了vux的原有picker组件,发现在华为自带浏览器中,效果依然能够实现. ...

  10. CEntOS6.5从启动界面直接进入命令行界面

    ctrl + alt + F1 ctrl + alt + F2 ctrl + alt + F3 ctrl + alt + F4 ctrl + alt + F5 ctrl + alt + F6 同时按下 ...