挺简单,生成素数表之后建个全素数的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. AP_总体业务及方案

    AP关键业务点说明 关键业务点 说明 预付款余额收回 1. 在应付款管理系统中输入一张虚拟发票,该发票的目的是在系统中冲减对供应商的预付款额,其金额等于预付款的未核销金额,供应商为原供应商. 借:其他 ...

  2. .Net 2.0自带的Json序列化、反序列化方法

    public class JsonUtil    {        public static T DeserializeObject<T>(string json)        {   ...

  3. Redis学习笔记--五种数据类型的使用场景

    String 1.String 常用命令: 除了get.set.incr.decr mget等操作外,Redis还提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一 ...

  4. library not found for -lPods 的解决办法

    在老项目工程中使用cocoapods,可能会报这个错误:library not found for -lPods . 导致这个错误可能有两个原因,这两个原因在编译过程中都是有蛛丝马迹可循的. 原因1: ...

  5. .NET对象与Windows句柄(二):句柄分类和.NET句柄泄露的例子

    上一篇文章介绍了句柄的基本概念,也描述了C#中创建文件句柄的过程.我们已经知道句柄代表Windows内部对象,文件对象就是其中一种,但显然系统中还有更多其它类型的对象.本文将简单介绍Windows对象 ...

  6. Top 10 Free Wireless Network hacking/monitoring tools for ethical hackers and businesses

    There are lots of free tools available online to get easy access to the WiFi networks intended to he ...

  7. 高效的两段式循环缓冲区──BipBuffer

    Simon Cooke,美国 (原作者) 北京理工大学 20981 陈罡(翻译) 写在前面的话: 循环缓冲区是一个非常常用的数据存储结构,已经被广泛地用于连续.流数据的存储和通信应用中.对于循环缓冲区 ...

  8. IE6不支持position:fixed属性

    _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.d ...

  9. 用Intellij IDEA 创建第一个maven项目!

    1. 一直想如何复用以前项目的maven的jar包! 其实只要拿到pom.xml即可!!! 1.1 创建一个maven项目 2. 3. 创建项目名和项目路径,我给项目起的名字是mavenV1.0 4. ...

  10. 《JAVA NIO》Channel

    3.通道 Channle主要分为两类:File操作对应的FIleChannel和Stream操作对应的socket的3个channe. 1.这3个channel都是抽象类.其具体实现在SPI里面. 2 ...