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

求助啊···为啥老是WA啊···麻烦看看哪错了啊···

Posted by xiaowan91 at 2011-07-30 09:50:17 on Problem 2739
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int a[10000];
int i,j,sum,k=0,n,t;
int fun(int n)
{
 int m=(int)sqrt(n);
 for(j=2;j<=m;j++)
 if(n%j==0) break;
 if(j>m){ a[k]=n;k++;}    
  return 0;  
    
}
int main()
{
  for(i=2;i<=10000;i++)
  fun(i);
 //  for(i=0;i<k;i++)
 // printf("%d ",a[i]);
 // printf("\n");
 // printf("%d\n",k);
  
 
  while(scanf("%d",&n)!=EOF)
{
    if(n==0)break;
      if(n>9973)printf("0\n");
   else                         
 {                                 
           sum=0;                       
     for(i=0;i<=n;i++)
    {
     if(a[i]>n)break;
     if(a[i]==n) {sum++;break;}                        
    }                         
    	
     while(i>0)
	  {
		t=n;
		j=i--;
		while(j>0&&(t-a[j-1])>=0)
		  {
		    t-=a[j-1];
		    if (t<0) break;
	        else if (t==0)	
		       sum++;
				j--;
		   }
	   }
		printf("%d\n",sum);
    } 	
}
/* */ 
    system("pause");
    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