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

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

Poj 2739

2019-11-14 08:46:35
字體:
來源:轉載
供稿:網友

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;	}	}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 如东县| 龙川县| 澄城县| 宜章县| 瓦房店市| 怀安县| 新河县| 观塘区| 麦盖提县| 屯昌县| 工布江达县| 云和县| 云龙县| 灵寿县| 铅山县| 新疆| 扶风县| 铜梁县| 黄骅市| 建昌县| 扬中市| 灵川县| 砀山县| 望城县| 泰安市| 张家口市| 青铜峡市| 汝城县| 金华市| 安庆市| 石阡县| 沂水县| 陈巴尔虎旗| 三明市| 桓仁| 吐鲁番市| 浙江省| 迁西县| 通州区| 合阳县| 松溪县|