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 skogt at 2010-02-27 14:27:53 on Problem 2909
#include<stdio.h>
int gen(int n);
int prime(int n);
int main()
{
	int n;
	while(scanf("%d",&n)&&n!=0)
		printf("%d\n",gen(n));
	return 0;
}
int gen(int n)
{
	int i,count=0;
	for(i=2;i<=n/2;i++)
		if(prime(i)&&prime(n-i))
			count++;
	return count;
}
int prime(int n)
{
	int i;
	for(i=2;i<=n/2;i++)
		if(n%i==0)	return 0;;
	return 1;	 
}

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