View Code of Problem 3836

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
struct num{
	int a;
	int b;
	int ab;
};
bool cmp(num a,num b){
	return a.ab<b.ab;
}
int main(){
	
	int gc,lc;
	while(cin>>gc>>lc){
		int motiab=gc*lc;
		num a[1000]={};
		int count=0;
		for(int i=gc;i<=sqrt(motiab*1.0);i++){
			if(motiab%i==0&&__gcd(i,motiab/i)==gc){
				a[count].a=i;
				a[count].b=motiab/i;
				a[count].ab=a[count].a+a[count].b;
				count++;
			}
		}
		sort(a,a+count,cmp);
		cout<<a[0].a<<" "<<a[0].b<<endl; 
		
	}
	return 0;
} 
/*
Main.cc: In function 'int main()':
Main.cc:21:19: error: 'sqrt' was not declared in this scope
   for(int i=gc;i<=sqrt(motiab*1.0);i++){
                   ^~~~
Main.cc:21:19: note: suggested alternative: 'qsort'
   for(int i=gc;i<=sqrt(motiab*1.0);i++){
                   ^~~~
                   qsort
*/

Double click to view unformatted code.


Back to problem 3836