poj 2739(筛法求素数)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 21613 | Accepted: 11837 | 
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
input is a sequence of positive integers each in a separate line. The
integers are between 2 and 10 000, inclusive. The end of the input is
indicated by a zero.
Output
output should be composed of lines each corresponding to an input line
except the last zero. An output line includes the number of
representations for the input integer as the sum of one or more
consecutive prime numbers. No other characters should be inserted in the
output.
Sample Input
2
3
17
41
20
666
12
53
0
Sample Output
1
1
2
3
0
0
1
2
Source
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define N 10000
int n,m,pr[N],a=;
bool p[N];
void gcd(){
for(int i=;i<N;i++){
if(!p[i]){ pr[a++]=i;}
for(int j=i*i;j<N;j+=i)
p[j]=true;
}
} int main(){
//freopen("in.txt","r",stdin);
memset(p,false,sizeof(p));
gcd();
while(cin>>n,n){
int j=,sum;m=;
for(int i=;i<a;i++){
sum=;j=i;
while(sum<n){
sum+=pr[j++];
}
if(sum==n)
m++;
}
printf("%d\n",m);
}
return ;
}
poj 2739(筛法求素数)的更多相关文章
- POJ 2689 筛法求素数
		DES:给出一个区间[L, U].找出这个区间内相邻的距离最近的两个素数和距离最远的两个素数.其中1<=L<U<=2147483647 区间长度不超过1000000. 思路:因为给出 ... 
- poj 2262 筛法求素数(巧妙利用数组下标!)
		Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41582 Accepted: ... 
- 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)
		算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ... 
- hdu 4548 筛法求素数 打表
		题目:http://acm.hdu.edu.cn/showproblem.php?pid=4548 Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题 ... 
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
		Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ... 
- 筛法求素数Java
		输出:一个集合S,表示1~n以内所有的素数 import java.util.Scanner; public class 筛法求素数 { public static void main(String[ ... 
- Algorithm --> 筛法求素数
		一般的线性筛法 genPrime和genPrime2是筛法求素数的两种实现,一个思路,表示方法不同而已. #include<iostream> #include<math.h> ... 
- JD  题目1040:Prime Number (筛法求素数)
		OJ题目:click here~~ 题目分析:输出第k个素数 贴这么简单的题目,目的不清纯 用筛法求素数的基本思想是:把从1開始的.某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉.剩下 ... 
- 2018牛客网暑期ACM多校训练营(第三场) H - Diff-prime Pairs - [欧拉筛法求素数]
		题目链接:https://www.nowcoder.com/acm/contest/141/H 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ... 
- 埃氏筛法求素数&构造素数表求素数
		埃氏筛法求素数和构造素数表求素数是一个道理. 首先,列出从2开始的所有自然数,构造一个序列: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1 ... 
随机推荐
- spoj104 highways 生成树计数(矩阵树定理)
			https://blog.csdn.net/zhaoruixiang1111/article/details/79185927 为了学一个矩阵树定理 从行列式开始学(就当提前学线代了.. 论文生成树的 ... 
- 【BZOJ】3329: Xorequ
			[题意]给定方程x^3x=2x,求<=x和<=2^x的满足方程的正整数个数. [算法]数位DP,矩阵快速幂 [题解]异或相当于不进位加法. 移项得,x^2x=3x,又因为x+2x=3x,所 ... 
- JS高级之面试必须知道的几个点
			1.函数的3种定义方法 1.1 函数声明 //ES5 function getSum(){} function (){}//匿名函数 //ES6 ()=>{}//如果{}内容只有一行{}和ret ... 
- 数据分析之CE找数据大法
			一.基本介绍 CE的全称为Cheat Engine,是一款内存修改编辑工具,其官网是http://www.cheatengine.org,可以在其官网下载到最新的CE工具,目前最新版本是Cheat E ... 
- bzoj 1305 二分+最大流判定|贪心
			首先我们二分一个答案mid,在判定是否能举办mid次,那么对于每个次我们可以用最大流根据是否满流(流量为n*mid)来判定,对于每个点我们拆成两个点,分别表示这个人要和他喜欢和不喜欢的人一起跳舞,那么 ... 
- bzoj 1084 DP
			首先对于m==1的情况非常容易处理(其实这儿因为边界我错了好久...),直接DP就好了,设f[i][k]为这个矩阵前i个选k个矩阵的最大和,那么f[i][k]=max(f[j][k-1]+sum[j+ ... 
- URI设计原则
			以下是与 REST API 相关的重要术语: 资源(Resource) 是一个对象或对某物的表示.它有一些相关联的数据,并有一组方法进行操作. 例如:动物,学校和员工是资源.这些资源都有着删除,添加, ... 
- Vue基本指令
			模板对象 vue指令 一:模板对象 <!DOCTYPE html> <html lang="en"> <head> <meta chars ... 
- 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力
			题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ... 
- (转) Spring源码阅读 之 Spring整体架构
			标签(空格分隔): Spring 声明:本文系转载,原地地址:spring framework 4 源码阅读 Spring骨架 Spring的骨架,也是Spring的核心包.主要包含三个内容 cont ... 
