View Code of Problem 3836

#include<stack>
#include<queue>
#include<iostream>
#include<cmath>

using namespace std;

typedef struct s_{
    int a;
    int b;
    int min;
}S;
int lcm(int at,int bt){

    return 0;
}
int gcd(int at,int bt){
    while(bt!=0){
        int k=at%bt;
        at=bt;
        bt=k;
    }
    return at;
}

int main(){
    int x,y;
    while(cin>>x>>y){
        S s;
        if(x<=y){
            s.a=x;
            s.b=y;
            s.min=x+y;
            }
        else{
            s.a=y;
            s.b=x;
            s.min=x+y;
            }
        for(int i=x;i<=y&&i<=sqrt(x*y);i++){
            if((x*y)%i==0){
                int j=x*y/i;
                if(gcd(j,i)==x){
                    if(i+j<s.min){
                        s.min=i+j;
                        s.a=i;
                        s.b=j;
                    }
                }
            }
        }
        printf("%d %d\n",s.a,s.b);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3836