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 ...
随机推荐
- [ios] 如何调用其他app h5界面调用打开app
参考资料:app唤醒app h5唤醒app 有趣的URL Scheme 被唤起端需要做的工作(demoApp): 1.设置URL Scheme 只是一个app的标识 具体是什么自己定 一个Sch ...
- django前端到后端一次完整请求实例
一.创建项目:# django-admin startproject mysite# cd mysite# python manage.py startapp blog 目录结构: 一.html文件: ...
- php基础-------preg_replace()与preg_replace_callback()
1.preg_replace() 执行一个正则表达式的搜索和替换. 语法: mixed preg_replace ( mixed $pattern , mixed $replacement , mix ...
- day09-2 字典,集合的内置方法
目录 字典的内置方法 作用 定义方式 方法 优先掌握 需要掌握 存储一个值or多个值 有序or无序 可变or不可变 集合的内置方法 作用 定义方式 方法 存储一个值or多个值 有序or无序 可变or不 ...
- jquery.nicescroll.min.js滚动条插件的用法
1.jquery.nicescroll.min.js源码 /* jquery.nicescroll 3.6.8 InuYaksa*2015 MIT http://nicescroll.areaaper ...
- 小试牛刀之sort()排序的实现
受大学室友的鼓动,我也打算利用公众平台来记录自己的前端知识积累,同时呢,自己总结的东西,总归会有局限性,希望小伙伴能给我指点迷津.知识就是一张巨大的网,作为一名摸不清头绪的入学者,唯一能做的事情就是吐 ...
- js解决跨域问题
JavaScript中的常见解决跨域的方法 1. 通过jsonp跨域 1.)原生实现: 2. document.domain + iframe跨域 此方案仅限主域相同,子域不同的跨域应用场景. 1.) ...
- 【codeforces 508E】Artur and Brackets
[题目链接]:http://codeforces.com/problemset/problem/508/E [题意] 让你构造一个括号字符串; 使得每个从左往右数第i个左括号在这个括号序列中与之匹配的 ...
- 楼宇自控-RS232\RS485\RS422
1.rs-232-c rs-232-c是美国电子工业协会eia(electronic industry association)制定的一种串行物理接口标准.rs是英文"推荐标准"的 ...
- POJ 1306
其实求的这个数的式子化简一下,就是C(N,M)..... #include <iostream> #include <algorithm> #include <cstdi ...