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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Poj 2739

2019-11-14 09:37:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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篩法求素?cái)?shù) 求連續(xù)素?cái)?shù)的和=?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;	}	}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 五寨县| 西乡县| 延长县| 安国市| 依安县| 东乌| 泸溪县| 广宁县| 大港区| 新余市| 曲周县| 保靖县| 兰考县| 涟源市| 永川市| 石狮市| 桐庐县| 长顺县| 西畴县| 东方市| 武城县| 昌宁县| 北碚区| 桐庐县| 利川市| 乐昌市| 绥江县| 新晃| 三门县| 新野县| 三台县| 天津市| 建昌县| 女性| 新津县| 平塘县| 洪洞县| 永宁县| 九龙县| 东丽区| 沙洋县|