poj 2739 Sum of Consecutive Prime Numbers 小结
three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime
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
integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.
#include<stdio.h> #include<cmath> using namespace std; long i,j,a[1230],n; bool p(long k) { for (long i=2;i<=trunc(sqrt(k));i++) if (k%i==0) return false; return true; } int main() { for (i=1;i<=1229;i++) a[i]=0; long cnt=1;a[cnt]=2; for (i=3;i<=10000;i++) if (p(i)){cnt++;a[cnt]=a[cnt-1]+i;} scanf("%ld",&n); while (n!=0) { long ans=0; for (i=1;i<=cnt;i++) for (j=i;j<=cnt;j++) { if (a[j]-a[i-1]==n) ans++; else if (a[j]-a[i-1]>n) break; } printf("%ld\n",ans); scanf("%ld",&n); } return 0; }
poj 2739 Sum of Consecutive Prime Numbers 小结的更多相关文章
- 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(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- 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 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- 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 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
随机推荐
- Android零碎知识(一)
public abstract Resources getResources () Return a Resources instance for your application's package ...
- Oracle 只导出某个用户下的表及数据
今天某大牛问我要之前我参与的一个系统的代码及库,我捣鼓下,发给了他. 他很诧异的问:这个库有这么大么 我说 因为当时是专门新建了一个实例,用户也是系统用户,所以导出的时候是导出的整个数据库 他 ZZ ...
- .net操作InI文件
public class INI { public static string IniFileName = "";//路径 [DllImport("kernel32&qu ...
- nginx+tomcat集群负载均衡(实现session复制)
转自:http://talangniao.iteye.com/blog/341512 架构描述 前端一台nginx服务器做负载均衡器,后端放N台tomcat组成集群处理服务,通过nginx转发到后面( ...
- Unix文化--RTFM
背景 从上个世纪70年代初unix被创建后的不久,它变得越来越流行起来,从最初的贝尔实验室,到后来的许多大学的计算机院系.这意味着越来越多的人需要学习如何使用unix. 可以预期的是,贝尔实验室的人都 ...
- VR全景智慧城市,开启“上帝视角”体验‘身临其境’
VR全景把不同的场景 分为若干个VR视角点 进入一个视角点,用户便能开启"上帝视角" 转动手机,身临其境地360度转动察看,对场景的全貌和细节一目了然. 人生处处有尴尬 比如大 ...
- VMware Workstation 11安装
VMware Workstation 11序列号:1F04Z-6D111-7Z029-AV0Q4-3AEH8
- 链表插入和删除,判断链表是否为空,求链表长度算法的,链表排序算法演示——C语言描述
关于数据结构等的学习,以及学习算法的感想感悟,听了郝斌老师的数据结构课程,其中他也提到了学习数据结构的或者算法的一些个人见解,我觉的很好,对我的帮助也是很大,算法本就是令人头疼的问题,因为自己并没有学 ...
- iptables实用教程(一):基本概念和原理
概述 iptables是linux自带的防火墙软件,用于配置IPv4数据包过滤或NAT(IPv6用ip6tables). 在linux上,防火墙其实是系统内核的一部分,基于Netfilter构架,基本 ...
- JAVAEE学习——struts2_03:OGNL表达式、OGNL与Struts2的结合和练习:客户列表
一.OGNL表达式 1.简介 OGNL:对象视图导航语言. ${user.addr.name} 这种写法就叫对象视图导航. OGNL不仅仅可以视图导航.支持比EL表达式更加丰富的功能. 2.使用OG ...