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 ...
随机推荐
- logstash json和rubydebug 第次重启logstash都会把所有的日志读完 而不是只读入新输入的内容
查看一下agent端的shipper的配置: # cat logstash_test2.shipper.conf input { file { path => ["/apps/logs ...
- Delphi编程建议遵守的规范2---命名规范
1.1.形参命名建议 所有形参的名称都应当表达出它的用途.如果合适的话,形参的名称最好以字母a 为前缀,例如: procedure SomeProc(aUserName:string; aUserAg ...
- Installing MySQL Server on CentOS
MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...
- BOOL in Object-C
BOOL in Object-C typedef signed char BOOL; #define YES (BOOL)1 #define NO (BOOL)0 重构上页中的代码 - (BOOL)s ...
- W-数据库基础
数据库系统由三部分组成:数据库(DB).数据库管理系统(DBMS)和数据库应用系统 数据加是用来存储数据的,里面存储两大类数据:用户数据及系统数据/数据字典,具体为系统中的用户以及用户孤权限,各种统计 ...
- HR外包系统 - 员工项目 薪资项目 考勤项目 -管理
项目管理-包括员工项目 薪资项目 考勤项目 一 后台总公司定义项目-前台分公司选择项目,定义别名-分公司客户选择员工项目,定义别名 分公司下面-新建薪资类别-薪资类别下面选择要的薪资和考勤项目. 二 ...
- eclipse项目中关于导入的项目里提示HttpServletRequest 不能引用的解决办法
eclipse项目中关于导入的项目里提示HttpServletRequest 不能引用的解决办法 当使用eclipse导入外部的web工程时,有时会提示HttpServletRequest, Serv ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- 剑指offer系列——二维数组中,每行从左到右递增,每列从上到下递增,设计算法找其中的一个数
题目:二维数组中,每行从左到右递增,每列从上到下递增,设计一个算法,找其中的一个数 分析: 二维数组这里把它看作一个矩形结构,如图所示: 1 2 8 2 4 9 12 4 7 10 13 6 8 11 ...
- 程序员应该是使用git
我来梳理下我想用git做的事情应该拥有那些功能: 本地的git命令以及图形界面,好让我在没有联网的时候创建git版本控制记录历史功能 一个github账号,好让我可以把本地的git仓库同步到那里 功能 ...