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 IceAngel at 2005-05-24 21:12:58 on Problem 2429
#include "iostream.h"
#include "math.h"

bool primeEachOther( unsigned long m , unsigned long n )
{
	unsigned long d;
	unsigned long i;
	if( m > n )
		d = n;
	else
		d = m;
	for( i = 2 ; i <= d ; i++ )
		if( m % i == 0 && n % i == 0 )
			return false;
	return true;
}
int main()
{
	unsigned long m , n;
	unsigned long d , t, min , i , j;
	unsigned long x , y;
	while( cin >> m >> n )
	{
		d = n / m;
		min = 0xffffffff;
		for( i = 1 ; i <= sqrt( d ) ; i++ )
		{
			if( d % i == 0 )
			{
				j = d / i;
				if( !primeEachOther( i , j ) )
				{
					continue;
				}
				t = i + j;
			
				if( t < min )
				{
					min = t;
					x = i;
					y = j;
				}
			}
		}
		cout<<m*x<<" "<<m*y<<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