国产探花免费观看_亚洲丰满少妇自慰呻吟_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;	}	}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 土默特右旗| 绍兴县| 屏南县| 天台县| 左权县| 庆安县| 盐山县| 汉阴县| 民县| 得荣县| 卢湾区| 柘城县| 山阳县| 安阳县| 余姚市| 博野县| 丹寨县| 辽中县| 越西县| 阿拉尔市| 神农架林区| 沙田区| 长沙县| 咸丰县| 平顺县| 赣州市| 遂平县| 恩平市| 大姚县| 措美县| 内乡县| 双城市| 武汉市| 平山县| 家居| 大田县| 邻水| 类乌齐县| 丁青县| 屏东市| 景谷|