ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
2
3
17
41
20
666
12
53
0
Sample Output
1
1
2
3
0
0
1
2
/*/
题意:
求连续素数和.
有多少种方法可以选取连续的素数,使这些数的和正好为n 思路:
1到10000的素数表打出来,然后直接尺取就可以了,很简单的一道题目。
/*/
#include"map"
#include"cmath"
#include"string"
#include"cstdio"
#include"vector"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;
typedef long long LL;
const int MX=1000005;
#define memset(x,y) memset(x,y,sizeof(x))
#define FK(x) cout<<"【"<<x<<"】"<<endl int vis[MX];
int prim[MX];
int ans[MX];
int main() {
int n,len=0,sum=0;
for(int i=2; i<=100; i++)
if(!vis[i])
for(int j=2; j<=10000; j++)
vis[j*i]=1;
for(int i=2; i<=10000; i++)
if(vis[i]==0) {
len++;
prim[len]=i;
}
for(int i=1; i<=len; i++) {
sum=0;
int j=i;
while(sum<=10000 && j<=1229) {
sum+=prim[j];
if(sum>10000)
break;
ans[sum]++;
j++;
}
}
while(~scanf("%d",&n)) {
if(!n)break;
printf("%d\n",ans[n]);
}
return 0;
}
ACM: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> # ...
- 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( *【素数存表】+暴力枚举 )
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 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
随机推荐
- gitlab 用户头像不能显示的问题
[root@GitLab assets]# cat /etc/gitlab/gitlab.rb # Change the external_url to the address your users ...
- EChart使用简单介绍
Echart是百度研发团队开发的一款报表视图JS插件,功能十分强大,使用内容做简单记录:(EChart下载地址 http://echarts.baidu.com/download.html) 1.ti ...
- [Tips] JavaScript 使用hash 对象传参
转自Web 前端开发修炼之道. 在JavaScript 中funciton 包含多个参数的时候,我们想要实现可选参数的功能,传很多个null 其实是个很讨厌的事情,这个时候就可以使用这个技巧. 具体见 ...
- Win10 VS2015 社区版切换到VS2013社区版 进行维护之前的项目
前提:当先在Win10 OS 安装了vs2015之后开发Win UAP,之后要维护之前的WP8 版本,安装了VS2013社区版 打开后 1问.Exception from HRESULT: 0x897 ...
- hdu 4028 2011上海赛区网络赛H dp+map离散
一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...
- c语言运算符号的优先级
c语言运算符号的优先级 本文来自百度搜索只为查看方便 优先级等级口诀: 圆方括号.箭头一句号, 自增自减非反负.针强地址长度, 乘除,加减,再移位, 小等大等.等等不等, 八位与,七位异,六位或,五与 ...
- 高效jQuery的奥秘
讨论jQuery和javascript性能的文章并不罕见.然而,本文我计划总结一些速度方面的技巧和我本人的一些建议,来提升你的jQuery和javascript代码.好的代码会带来速度的提升.快速渲染 ...
- loj 1379(最短路变形)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27087 思路:题目的意思是求S->T的所有路径中花费总和小于 ...
- MapKit地图划线
只要用于获取用户位置都要取得用户授权 #import "ViewController.h" #import <MapKit/MapKit.h> @interface V ...
- 实现Web验证码图片-原理
实现验证码的基础 GDI+ graphics device interface plus的缩写,即图形设备接口.GDI+为开发者提供了一组实现与各种设备(具有图形化能力但不涉及图形细节的设备)进行交互 ...