UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)
写个素数筛暴力打表一波就AC了;
#include <iostream>
using namespace std;
const int N = 10001;
int i, j, NotPrime[N];
long long sum[N];
void GetNotPrime()
{
for( i=2; i<=N; i++ )
if( !NotPrime[i] )
for( j = i+i; j<=N; j+=i )
NotPrime[j] = 1;
}
int k;
void GetPrimeSum()
{
sum[0] = 0;
sum[1] = 2;
k = 1;
for( i=3; i<N; i++ )
if( !NotPrime[i] )
{
sum[k+1] = sum[k] + i;
k++;
}
}
int main()
{
int n;
GetNotPrime();
GetPrimeSum();
while( cin >> n && n )
{
int cnt = 0;
for( i=0; i<k; i++ )
{
for( j=i+1; j<k; j++)
{
if( n == sum[j] - sum[i] )
{
cnt++;
}
}
}
cout << cnt << endl;
}
return 0;
}
UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)的更多相关文章
- 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 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- 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(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25225 ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- Sum of Consecutive Prime Numbers(poj2739)
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22019 Ac ...
随机推荐
- 待解决:2bootstrap-cerulean.css Failed to load resource: the server responded with a status of 404 ()
2bootstrap-cerulean.css Failed to load resource: the server responded with a status of 404 ()
- c linux ping 实现
摘自:https://blog.csdn.net/weibo1230123/article/details/79891018 ping的实现和代码分析一.介绍 ping命令是用来查看网络上另一 ...
- "软掩膜"和“硬掩膜”-智能IC卡
目录 一.“软掩膜”和“硬掩膜”... 2 二.EMV迁移进程... 3 三.PBOC规范和EMV规范对比... 3 四.总结... 5 五.关于SDA和DDA. 6 一.“软掩膜”和“硬掩膜” “软 ...
- Go 网络编程笔记
前言: 本文是学习<<go语言程序设计>> -- 清华大学出版社(王鹏 编著) 的2014年1月第一版 做的一些笔记 , 如有侵权, 请告知笔者, 将在24小时内删除, 转载请 ...
- wireshark问题
上一篇wireshark编译成功了,生成了相应的wireshark.exe,dumpcap.exe等可执行文件(这些文件都是可以运行的),编译工具用的是VS2010,但是新生成的文件和文件夹中没有找到 ...
- Inno Setup创建快捷方式跟快速运行栏快捷方式
[Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescrip ...
- Yii2 修改 breadcrumb 首页图标
<?=Breadcrumbs::widget([ 'homeLink' => [ 'label' => '<i class="fa fa-home"> ...
- 51建设Android版一些技术整理
不知不觉几个月就过去了,新项目已经发了两个大的版(其实已经迭代了3版),趁着项目新版刚刚上线闲下来的时间整理下用到的技术点. 整体架构 采用MVP Android官方MVP架构示例项目解析 推荐一个插 ...
- KindEditor3.x整合教程-Xproer.WordPaster
版权所有 2009-2017 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/wordpa ...
- 使用火蜘蛛采集器Firespider采集天猫商品数据并上传到微店
有很多朋友都需要把天猫的商品迁移到微店上去.可在天猫上的商品数据非常复杂,淘宝开放接口禁止向外提供数据,一般的采集器对ajax数据采集的支持又不太好. 还有现在有了火蜘蛛采集器,经过一定的配置,终于把 ...