Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么错,举个反例啦.....#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator