Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

刚开始题目没有看清楚以为不连续的素数也可以,然后还开数组时少写了个0,现在终于AC了,贴上代码

Posted by denganliang at 2011-03-19 21:48:36 on Problem 2739
#include<stdio.h>
#include<math.h>
int a[10010];
int main(){
	int i,count,j,n=0,b,temp,flag=0;
	a[n++]=2;
	for(i=3;i<=10010;i++){
		for(j=2;j<=floor(i/2);j++)
		   if(i%j==0) break;
		if(j>floor(i/2)) a[n++]=i; 
		}
    while(1){
		flag=0;
		count=0;
		scanf("%d",&b);
		if(b==0) break;
		for(i=0;a[i]<=b&&i<n;i++)
		{
			temp=0;
			for(j=i;a[j]<=b&&j<n;j++)
			 {
				  temp+=a[j];
			 if(temp==b)
			  {
				  count++;
				  flag=1;
				  break;
				  } 
		      if(temp>b) break;
				  }
			}
		if(flag==0) printf("0\n");
        else printf("%d\n",count);
		}
	return 0;
	}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator