国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Poj 2739

2019-11-14 09:02:30
字體:
來源:轉載
供稿:網友

http://poj.org/PRoblem?id=2739

Sum of Consecutive Prime Numbers
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 24310 Accepted: 13228

Description

Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has 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

The 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

The 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

2317412066612530

Sample Output

11230012

Source

Japan 2005篩法求素數 求連續素數的和=?n
#include<iostream>using namespace std;int a[10001]={0},i,j;void primer(int a[]){	for(i=2;i<10001;i++)	   for(j=i+i;j<10001;j+=i)	   {	   	  if(j%i==0) a[j]=1;	   }	}int main(){	int p[10001],t=0;	primer(a);	for(i=2;i<10001;i++)	{		if(a[i]==0) p[t++]=i;	}	/*cout<<t<<endl;	for(i=0;i<t;i++)	  cout<<p[i]<<" ";*/	int n;	while(cin>>n,n!=0)	{		int sum=0,temp=0,m=0;		for(i=0;i<10001;i++)		{   if(p[i]>n) break;		    sum=0;		   for(j=i;j<10001;j++)		   {		   	 sum+=p[j];		   	 if(sum==n) m++;		   	 if(sum>n) break;		  }  			}		cout<<m<<endl;	}	}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宾阳县| 手游| 延津县| 神木县| 丰县| 河源市| 兰坪| 民权县| 台南市| 侯马市| 郸城县| 蛟河市| 镶黄旗| 明星| 巴南区| 临沂市| 南阳市| 宝应县| 赤水市| 仲巴县| 清远市| 屏山县| 土默特左旗| 巴东县| 涞水县| 额济纳旗| 商河县| 澎湖县| 武邑县| 武乡县| 芒康县| 黎平县| 太湖县| 霸州市| 依安县| 前郭尔| 平山县| 依兰县| 乌兰浩特市| 新和县| 监利县|