View Code of Problem 3836

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int main(){
	int m,n;
	while(cin>>m>>n){
		int sum=m*n;
		int min=1e9;
		int a,b;
		for (int i=m;i<=sqrt(sum);i++){
			if(sum%i!=0)
			continue;
			int temp=sum/i;
			if(gcd(i,temp)==m){
				if(temp+i<min){
					min=temp+i;
					a=i;
					b=temp;
				}
			}
			
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3836