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. 「题目代码」P1054~P1059(Java)

    P1054 猴子吃桃 import java.util.*; import java.io.*; import java.math.BigInteger; import java.lang.Chara ...

  2. hdu2553N皇后问题(dfs,八皇后)

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. 怎样下载Firefox与Chrome浏览器驱动

    在浏览器地址栏输入https://www.seleniumhq.org/ 打开Selenium官网 下载Firefox浏览器驱动 解压到本地 下载Chrome浏览器驱动 解压到本地 把这2个驱动放到P ...

  4. 167. Add Two Numbers【LintCode by java】

    Description You have two numbers represented by a linked list, where each node contains a single dig ...

  5. 中文乱码的处理—@北河的ppt

  6. 同台服务器 部署多个tomcat 需要做的修改

    需要修改以下加粗部分: 1:访问端口 8080->8081 2:shutdown 端口 8005->8015 3: AJP端口 8001->8010 <?xml version ...

  7. Attention注意力机制介绍

    什么是Attention机制 Attention机制通俗的讲就是把注意力集中放在重要的点上,而忽略其他不重要的因素.其中重要程度的判断取决于应用场景,拿个现实生活中的例子,比如1000个人眼中有100 ...

  8. [leetcode-667-Beautiful Arrangement II]

    Given two integers n and k, you need to construct a list which contains n different positive integer ...

  9. OSI七层协议模型及OSI参考模型中的数据封装过程

    转载自:http://blog.csdn.net/qq_14935437/article/details/71081546 OSI模型,即开放式通信系统互联参考模型(Open System Inter ...

  10. URAL 1664 Pipeline Transportation(平面图最大流)

    Description An oligarch Vovan, as many other oligarchs, transports oil from West Cuckooland to East ...