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

Re:0MS 标准的c语言写的... 不容易啊...

Posted by 12619 at 2009-07-24 11:44:06 on Problem 2739
In Reply To:0MS 标准的c语言写的... 不容易啊... Posted by:songsuoyuan at 2009-05-10 09:54:56
> #include<stdio.h>
> 
> int a[10010];
> int b[1229];
> 
> void createprime()
> {
> 	int i,j;
> 	for(i=2;i<10010;i++){
> 		if(a[i]==1)
> 			continue;
> 		for(j=2;i*j<10010;j++)
> 			a[i*j]=1;
> 	}
> 	j=0;
> 	for(i=2;i<10010;i++)
> 		if(a[i]==0){
> 			b[j]=i;
> 			j++;
> 		}
> }
> 
> int main()
> {
> 	createprime();
> 	int work,i,j,sum,p;
> 	while(1){
> 		scanf("%d",&work);
> 		if(work==0)
> 			break;
> 		p=0;
> 		for(i=0;b[i]<=work;i++){
> 			j=i;
> 			sum=0;
> 			while(1){
> 				sum+=b[j];
> 				if(sum==work){
> 					p++;
> 					break;
> 				}
> 				if(sum>work)
> 					break;
> 				j++;
> 			}
> 		}
> 		printf("%d\n",p);
> 	}
> 	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