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 ...
随机推荐
- javascript的constructor属性
/* constructor 属性 constructor 属性返回所有 JavaScript 变量的构造函数. */console.log("John".constructor) ...
- 15-Call to your teacher(有向图的连通判断)
链接:https://www.nowcoder.net/acm/contest/76/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- 读取位图(bitmap)实现及其要点
位图的格式如下: 1.文件头信息块 0000-0001 :文件标识,为字母ASCII码“BM”. 0002-0005 :文件大小. 0006-0009 :保留,每字节以“00”填写. 000A-000 ...
- Python获取服务器的厂商和型号信息-乾颐堂
Python获取服务器的厂商和型号信息,在RHEHL6下,需要系统预装python-dmidecode这个包(貌似默认就已经装过了) 脚本内容如下 [root@linuxidc tmp]# cat t ...
- tp5 whereOr
题目:查询grade=1 or class=2 or sex=3的学生 $condition[; $condition[; $condition[; $list =Db::name($this-> ...
- jquery页面初始化控件时间
this.InitControlTime = function () { if ($("#txt_Id_").val() == "") { var today ...
- ORM对象/关系模型
1 ORM 对象关系映射(ORM)提供了概念性的.易于理解的模型化数据的方法.ORM方法论基于三个核心原则: 简单:以最基本的形式建模数据. 传达性:数据库结构被任何人都能理解的语言文档化. 精确性: ...
- AngularJS基本使用
简介 AngularJS是Google开源的前端JS结构化框架 Angular关注的是动态展示页面数据, 并与用户进行交互.其主体不再是DOM,而是页面中的动态数据 AngularJS特性(优点) 双 ...
- [GO]ticker的使用
package main import ( "time" "fmt" ) //ticker是一个定时触发的计时器,它会以一个间隔往channel发送整一个事件( ...
- kalilinux系统设置
echo LANG="zh_CN.UTF-8" > /etc/default/locale