挺简单,生成素数表之后建个全素数的vector,然后。。随便玩咯

 #include <iostream>
 #include <stdio.h>
 #include <string>
 #include <stack>
 #include <map>
 #include <vector>
 #include <algorithm>
 using namespace std;

 ];

 void primes() {
     memset(prime, true, sizeof(prime));
     ; i < ; i++)
         if (prime[i])
             ; j * i < ; ++j) prime[i*j] = false;
 }

 int main()
 {
     primes();
     int n;
     vector<int> S;
     ; i < ; ++i)
         if (prime[i]) S.push_back(i);
     while (cin >> n && n) {
         ;
         ; S[i] <= n; ++i) {
             ;
             int cur = i;
             while (sum <= n) {
                 if (sum == n) {
                     ans++;
                     break;
                 }
                 else {
                     sum += S[cur];
                     cur++;
                 }
             }
         }
         cout << ans << endl;
     }

     ;
 }

poj: 2739的更多相关文章

  1. ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法

    POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. POJ.2739 Sum of Consecutive Prime Numbers(水)

    POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...

  3. POJ中和质数相关的三个例题(POJ 2262、POJ 2739、POJ 3006)

    质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能被其他自然数整除,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.      最小的质数 ...

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

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

  5. POJ 2739. Sum of Consecutive Prime Numbers

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

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

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

  7. POJ 2739 Sum of Consecutive Prime Numbers 难度:0

    题目链接:http://poj.org/problem?id=2739 #include <cstdio> #include <cstring> using namespace ...

  8. POJ 2739:Sum of Consecutive Prime Numbers(Two pointers)

    [题目链接] http://poj.org/problem?id=2739 [题目大意] 求出一个数能被拆分为相邻素数相加的种类 [题解] 将素数筛出到一个数组,题目转化为求区段和等于某数的次数,尺取 ...

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

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

  10. Greedy:Sum of Consecutive Prime Numbers(POJ 2739)

     素数之和 题目大意:一些整数可以表示成一个连续素数之和,给定一个整数要你找出可以表示这一个整数的连续整数序列的个数 方法:打表,然后用游标卡尺法即可 #include <iostream> ...

随机推荐

  1. linux指定目录安装软件后,程序找不到共享库问题

    以svn为例,64位centos yum install subversion --installroot=/usr/svn/后 执行svn命令,报错svn: error while loading ...

  2. extjs4 树列表 添加子节点 刷新所有父节点数据

    itemclick:function(view, record, item,index){console.log(record.parentNode) for(pNode = record.paren ...

  3. JS实现页面回到顶部效果

    [代码] <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  4. css3 loading效果

    file:///E:/zhangqiangWork/2014/SPDbank/index.html 参考该网站 http://tobiasahlin.com/spinkit/ 查看源代码把里面的dom ...

  5. java 中间件

    先说中间件:非底层操作系统软件.非业务应用软件,不是直接给最终用户使用的,不能直接给客户带来价值的软件,统称中间件.常见的有如下几种:服务中间件.集成中间件.数据中间件.消息中间件.安全中间件. 其中 ...

  6. 从printf("\40d\n")看转义字符

    1.  八进制  十进制  十六进制 二进制:0 1 2 3 4 5 6 7    \0(或省略0,\) ,\28 按道理是错误的,但是C语言把它解释为 \2,8错误了就不考虑 十进制:0 1 2 3 ...

  7. nginx端口被占用解决方案

    killall -9 nginx或service nginx restart(重新启动)

  8. 利用DBCC PAGE查看SQL Server中的表和索引数据

    16:08 2013-01-06 参考http://doc.chinaunix.net/sqlserver/200810/206034.shtmlDBCC PAGE|IND 参数 DBCC PAGE ...

  9. Sublime text 3 SVN插件及使用方法

    前提是你电脑里已装有SVN,这时只是设置快捷调用SVN. 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴对应版本的代码后回车安装 适用于 S ...

  10. Java多例设计模式

    class TrafficLight{ private String lightType; private static final TrafficLight GREENLIGHT = new Tra ...