简单的素数打表,然后枚举。开始没注意n读到0结束,TLE了回。。下次再认真点。A过后讨论里面有个暴力打表过的,给跪了!

 #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <complex.h>
#include <cmath>
using namespace std; const int N = ; bool is[N]; int prm[N];
int getprm (int n) {
int i, j, k = ;
int s, e = (int)(sqrt(0.0 + n) + );
memset (is, , sizeof (is));
prm[k ++] = ; is[] = is[] = ;
for (i = ; i < n; i += ) is[i] = ;
for (i = ; i < e; i += )
if (is[i]){
prm[k ++] = i;
for (s = i * , j = i * i; j < n; j += s) {
is[j] = ;
}
}
for (; i < n; i += ) {
if (is[i]) prm[k ++] = i;
}
return k;
} int main () {
getprm();
/*for (int i = 0 ; i < 100; ++ i) {
cout << i << ": ";
cout << prm[i] << endl;
}*/
// 1229个素数 0-1w
ios::sync_with_stdio(false);
cin.tie();
int n;
while (~scanf ("%d", &n)) {
if (n == ) break;
int sum, cnt = ;
for (int i = ; prm[i] <= n; ++ i) {
sum = ;
for (int j = i; prm[j] <= n; ++ j) {
sum += prm[j];
if (sum < n) {
continue;
} else if (sum == n) {
cnt ++;
break;
} else {
break;
}
}
}
printf ("%d\n", cnt);
}
return ;
}

【POJ2739】Sum of Consecutive Prime Numbers的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895 ...

  2. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  3. POJ2739 Sum of Consecutive Prime Numbers(尺取法)

    POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...

  4. 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 ...

  5. Sum of Consecutive Prime Numbers(poj2739)

    Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22019 Ac ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  8. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS   Memory Limit: 6 ...

  9. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

随机推荐

  1. 关于bootstrap--列表(ol、ul)

    1.list-unstyled : 在<ol>(有序列表)</ol><ul>(无序列表)</ul>中加入class="list-styled& ...

  2. 【Eclipse DDMS】 Can't bind to local 8600 for debugger

    问题原因: 电脑上同时安装了Eclipse 和Android Studio两个ide. 关键是使用eclipse adb连接真机时候,android studio也处于运行状态,后者默认也是要连接ad ...

  3. github atom 试用

    github的编辑器atom 1.0已经出来了,在https://atom.io/ 我之前在win上一直用notepad++写了两年脚本.最近改写lua了,项目组统一用的sublime text.su ...

  4. IOS 缩放图片常用方法

    /** * 指定Size压缩图片 (图片会压缩变形) * * @param image 原图 * @param size 压缩size * * @return 压缩后的图片 */ -(UIImage* ...

  5. 在 IIS 上创建 FTP 站点

    微软参考文档: 在 IIS 上生成 FTP 站点 主要过程: 1.控制面板 -> 程序 -> 启动或关闭Windows功能 -> 将Internet Information Serv ...

  6. 自己实现一个SQL解析引擎

    自己实现一个SQL解析引擎 功能:将用户输入的SQL语句序列转换为一个可运行的操作序列,并返回查询的结果集. SQL的解析引擎包含查询编译与查询优化和查询的执行,主要包含3个步骤: 查询分析: 制定逻 ...

  7. 区间DP(初步了解)

    区间动态规划问题一般都是考虑.对于每段区间,他们的最优值都 是由几段更小区间的最优值得到,是分治思想的一种应用,将一个区间 问题不断划分更小的区间直至一个元素组成的区间,枚举他们的组合  .求合并后的 ...

  8. Android TextView中实现点击文本超链接(无下划线)的封装类

    android中有的时候须要在TextView上设置一些超链接,点击这些超链接时进行一些操作.比如新浪微博上的一些keyword,点击时会跳转到对应的页面. 怎样实现我们就直接看源代码吧. /** * ...

  9. Dynamics CRM 2016 使用Plug-in Trace Log调试插件

    1.写插件 首先,让我们写一个简单的插件来测试新插件跟踪日志功能.请注意,在下面的示例代码中,我们增加ITracingService的一个实例,以及记录有关插件的执行信息记录的一些键值: 2.注册插件 ...

  10. 用SNMP协议实现系统信息监控--Windows Server 2008

    简单了解: SNMP简单网络管理协议,是一种属于应有层的协议,主要有三个部分组成,被管理部分.代理部分和网络管理系统. 被管理部分是一个网络节点,也称为网络单元.SNMP代理是被管理设备上的一个网络管 ...