poj: 2739
挺简单,生成素数表之后建个全素数的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的更多相关文章
- ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS Memory Limit:65536KB 64bit IO Fo ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- POJ中和质数相关的三个例题(POJ 2262、POJ 2739、POJ 3006)
质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能被其他自然数整除,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数. 最小的质数 ...
- 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 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
- POJ 2739 Sum of Consecutive Prime Numbers 难度:0
题目链接:http://poj.org/problem?id=2739 #include <cstdio> #include <cstring> using namespace ...
- POJ 2739:Sum of Consecutive Prime Numbers(Two pointers)
[题目链接] http://poj.org/problem?id=2739 [题目大意] 求出一个数能被拆分为相邻素数相加的种类 [题解] 将素数筛出到一个数组,题目转化为求区段和等于某数的次数,尺取 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- Greedy:Sum of Consecutive Prime Numbers(POJ 2739)
素数之和 题目大意:一些整数可以表示成一个连续素数之和,给定一个整数要你找出可以表示这一个整数的连续整数序列的个数 方法:打表,然后用游标卡尺法即可 #include <iostream> ...
随机推荐
- 利用js轻松实现页面简繁体转换
使用方法:StranBody(); //转换对象,使用递归,逐层剥到文本 function StranBody(fobj) { if(typeof(fobj)=="object") ...
- python join
# 对序列进行操作 ' '.join(['hello','good','boy','doiido']) hello:good:boy:doiido # 对字符串进行操作 ':'.join(" ...
- Average Cost (AVCO) Method
http://accountingexplained.com/financial/inventories/avco-method Average Cost (AVCO) Method Aver ...
- [LeetCode]题解(python):098 Validate Binary Search Tree
题目来源 https://leetcode.com/problems/validate-binary-search-tree/ Given a binary tree, determine if it ...
- [转]ANDROID L——Material Design详解(动画篇)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 转自:http://blog.csdn.net/a396901990/article/de ...
- imx6 生成 spi设备节点
开发板需要使用spi接口,但是spi接口被touch占用,使用event进行操作.所以需要更改配置,生成spi设备节点. 参考链接 https://community.nxp.com/thread/3 ...
- Spring AOP 实现原理与 CGLIB 应用
https://www.ibm.com/developerworks/cn/java/j-lo-springaopcglib/ AOP(Aspect Orient Programming),也就是面向 ...
- Mybatis在xml文件中处理大于号小于号的方法
第一种方法:用了转义字符把">"和"<"替换掉,然后就没有问题了. AND start_date <= CURRENT_DATE AND en ...
- POCO 是什么?
POCO(Plain Old C#/CLR Object),意为:纯老式的 C#/CLR 对象,也可以称为简单的 C#/CLR 对象,POCO 的概念来自于 POJO(Plain Old Java O ...
- iOS:使用Github托管自己本地的项目代码方式三(命令行方式: Terminal Line)
使用终端命令行将本地项目代码上传到github上进行托管 对于IOS开发者来说,Github的使用是必须要掌握的一种技能,而把项目由本地上传到Github有多种方式 1.开发工具Xcode配置Git, ...