Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 最明显的错就是用unsigned long，题目说了最大的数有2^63。题目都还没看清就不要对自己的程序那么有信心

Posted by frkstyc at 2005-05-24 21:44:23 on Problem 2429
In Reply To:为什么错，举个反例啦..... Posted by:IceAngel at 2005-05-24 21:12:58
```> #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: