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

各位大神,帮小弟看看怎么老是不对呢?

Posted by cui901022 at 2012-07-17 15:38:41 on Problem 2739
#include <stdio.h>

int  getprime(int a) 
{
	int i,j,count=1,flag,b[666],sum=0,k=0;
	b[0]=2;
	for(i=3;i<a+1;i++)       //找到小于等于a的所有质数,并放在数组b中 
	{
		flag=0;
		for(j=2;j<i;j++)
			if(i%j==0) 
			{
				flag=1;
				break;
			}
		if(flag=0)
		{
			b[count]=i;
			count++;
		}
	}
	for(i=0;i<count;i++)   //找出能代替a的表达式的个数 
	{
		sum=b[i];
		for(j=i;j<count;j++)
		{

			if(sum==a) 
			{
				k++;
				break;
			}
			else 
			{
				if(sum<a)
				{
					j++; 
					sum=sum+b[j];
				} 
				else break;
			}
		}
	}
	return k;
}

int main()
{
	int a,c[10],k;
	int i;
	for(i=0; ;i++)
	{
		scanf("%d",&a);
		if(a!=0)
		{
			c[i]=getprime(a);
			k=i+1;
		}
		if(a==0)
			break;
	}
	for(i=0;i<k;i++)
		printf("%d\n",c[i]);
}

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