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 zpdlut at 2010-09-10 09:21:49 on Problem 1411
#include<iostream>
#include<math.h>
using namespace std;
bool IsPrime(int n)
{
	int m = sqrt(n*1.0);
	for(int i=2;i<=m;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
int main()
{
	int m,a,b;
	while(cin>>m>>a>>b)
	{
		if(m+a+b==0)
			break;
		int bounds = sqrt(m*1.0);
		int max = 0;
		int p,q;
		for(int i=2;i<=bounds;i++)
		{
			if(!IsPrime(i))
				continue;
			int e = (i*b)/a;
			int min = m/i;
			if(e>min)
				e = min;
			for(int j=e;j>=i;j--)
			{
				if(IsPrime(j))
				{ 
					if(i*j>max)
					{
						max = i*j;
						p=i;
						q=j;
					}
					break;
				}
			}
		}
		cout<<p<<" "<<q<<endl;
	}
	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