POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数
用的筛法素数打表
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 20020 | Accepted: 10966 |
Description
Input
Output
Sample Input
2
3
17
41
20
666
12
53
0
Sample Output
1
1
2
3
0
0
1
2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int prime[10000],num[10005];
int main()
{
int i,j,k=0,tmp,n;
for(i=0;i<=10000;i++) num[i]=1;
num[0]=0;
num[1]=0;
for(i=2;i<=10000;i++)
{
if(num[i])
{
prime[k++]=i;
for(tmp=i*2;tmp<=10000;tmp+=i)
num[tmp]=0;
}
}
while(scanf("%d",&n)!=EOF&&n)
{
int ans=0,sum;
for(i=0;i<k;i++)
{
sum=0;
for(j=i;j<k&&sum<n;j++)
sum+=prime[j];
if(sum==n)
ans++;
}
printf("%d\n",ans);
}
}
POJ 2739 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(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- 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( *【素数存表】+暴力枚举 )
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 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 ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
随机推荐
- Centos7 minimal 系列之桥接模式联网(二)
一.桥接模式联网 之前用NAT模式连接网络,Centos是可以上网,而且Centos可以ping通主机,但是主机ping不通虚拟机.后来发现Nat模式只能由内而外. 1.1设置虚拟机的网络适配器 1. ...
- windows上上传代码到Github
Repository name: 仓库名称 Description(可选): 仓库描述介绍 Public, Private : 仓库权限(公开共享,私有或指定合作者) Initialize this ...
- Axure设计软件下载安装及注册
如图:本地计算机安装了两个版本的Axure,但8版的有问题,点击保存软件就退出了:7版本要想使用的注册授权 https://blog.csdn.net/botree_chan/article/deta ...
- Android 自定义ScrollView的滑动监听事件
项目结构: 1.LazyScrollView类(自定义ScrollView) package android.zhh.com.myapplicationscrollview; /** * Create ...
- PHP魔术方法__clone()篇
PHP中定义了一个内置方法__clone()来调整兑现的克隆行为: 当一个对象被克隆的时候会自动执行__clone()方法,而复制的对象可以在其方法内进行调整 header('Content-type ...
- 『转』How to Think About Your Career
开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...
- Json扩展 (转)
https://www.newtonsoft.com/json https://www.cnblogs.com/BrokenIce/p/5902441.html https://blog.csdn.n ...
- Ubuntu14.0 + CUDA9.0 + cudnn7.0 + TensorFlow-gpu1.7.0
在安装好nvidia驱动的基础上安装 CUDA9.0 + cudnn7.0 + TensorFlow-gpu1.7.0 这三个是匹配的版本 别的匹配(CUDA8.0 + cudnn6.0 + Tens ...
- 如何使用阿里云的yum源
这里需要有网.因为我们需要下载会用到wget [root@localhost ~]# iptables -F[root@localhost ~]# systemctl stop firewalld[r ...
- CSS Grid(CSS网格)
Grid被设计来做一些Flexbox不能做的事情,所以不是被设计来取代Flexbox的. flexbox 一维的 Grid 二维的 总结: Grid Items作用在Grid Container的直 ...