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 314236918 at 2009-08-09 11:29:29 on Problem 1411
#include<stdio.h>
#include <math.h>
int main()
{ 	
	int a[2000];
	int tp,num=0,m,c,b,p,q,n,i,j;
	double s;
for (i=2;i<9091;i++)
	{
		tp=0;
		for (j=2;j<=(int)sqrt(i);j++)
			if (i%j==0) {tp=1;break;}
		if (tp==0)
		{
			a[num]=i;
			num++;
		}
	}
	while(EOF!=scanf("%d%d%d",&m,&c,&b))
	{
while (m>0)
	{
		n=0;
		s=(double)c/b;
		for (i=num-1;i>=0;i--)
		{   if (a[i]>m) continue; 
			for (j=i;j<=num-1;j++)
			{
				if (a[j]>m||a[j]*a[i]>m||((double)a[i]/a[j])<s) break;
				if (a[j]*a[i]>n)
				{
					n=a[i]*a[j];
					p=a[i];
					q=a[j];
				}
			}
		}
          printf("%d %d\n",p,q);
	
	}
	}
	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