Sicily 1793. Numbers

来源:互联网 发布:淘宝哪家螺蛳粉好吃 编辑:程序博客网 时间:2024/04/30 14:23

没想到什么好办法,暴力解决……

Run Time: 0.05sec

Run Memory: 304KB

Code length: 630Bytes

SubmitTime: 2011-12-14 23:22:11

// Problem#: 1793// Submission#: 1078394// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <cstdio>#include <cmath>using namespace std;int gcd( int a, int b ) {    int temp;    while ( b != 0 ) {        temp = b;        b = a % b;        a = temp;    }    return a;}int main(){    int GCD, LCM;    int a, b;    while ( scanf( "%d%d", &GCD, &LCM ) && GCD && LCM ) {        for ( b = ceil( sqrtf( GCD * LCM ) ); true; b++ ) {            if ( GCD * LCM % b == 0 ) {                a = GCD * LCM / b;                if ( gcd( a, b ) == GCD )                    break;            }        }        printf( "%d %d %d\n", b - a, a, b );    }    return 0;}                                 


 

原创粉丝点击