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 |
最明显的错就是用unsigned long,题目说了最大的数有2^63。题目都还没看清就不要对自己的程序那么有信心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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator