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 ...
随机推荐
- SpringCloud04 服务配置中心、消息总线、远程配置动态刷新
1 环境说明 JDK:1.8 MAVENT:3.5 SpringBoot:2.0.5.RELEASE SpringCloud:Finchley.SR1 2 创建服务注册中心(Eureka服务端) 说明 ...
- [erlang 002]gen_server中何时会跑到terminate函数
一.从start方法产出的独立gen_server进程 实验代码: %%%-------------------------------------- %%% @Module : %%% @Auth ...
- Nginx 事件基本处理流程分析
说明:本文章重点关注事件处理模型.有兴趣的同学可以去http://tengine.taobao.org/book/查找更多资料.Tengine应该是淘宝基于Nginx自己做的修改.这个地址的文档还在不 ...
- python3--json反序列化
# Auther: Aaron Fan # 加载文件中的数据 import json with open('test.txt','r',encoding='utf-8') as f: info = j ...
- 对SOA架构思想的一些说明(转)
出处:http://kb.cnblogs.com/page/510698/ 从纵向到横向 传统业务系统的构建更多的是竖井式的纵向思想,这个主要是从单个业务系统孤立来看都是垂直应用.那么SOA架构的视角 ...
- 设计模式13:Template Method 模板方法模式(行为型模式)
Template Method 模板方法模式(行为型模式) 变与不变 变化——是软件永恒的主题,如何管理变化带来的复杂性?设计模式的艺术性和复杂度就在于如何分析,并发现体系中的变化点和稳定点,并使用特 ...
- Utimate Visual 2013 突然间无法新建项目工程解决
问题: 我用的Win7 安装的VS2013,这一段时间用的好好的,突然间新建工程师向导页面跳转不过去... 解决: 参考:http://stackoverflow.com/questions/1225 ...
- 文件查找记录类型 - TSearchRec - 文件操作(二)
SysUtils单元下的TSearchRec是一个记录类型,主要通过FindFirst, FindNext, and FindClose使用. 接上一篇举例说明TSearchRec常用成员 //sys ...
- MVC4 4种Filter
1. AuthorizationFilter: 从命名上看这个用于完成授权相关的工作. AuthorizationFilter 实现了 IAuthorizationFilter 接口, 如果我们希望执 ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...