3.1. 15이원준 ¶
#include<iostream>
using namespace std;
int checker(int f, int s){
int answer;
for(int i = 1; i*i<= f; i++){
if(f%i == 0 && s%i == 0){
answer = i;
}
}
return answer;
}
int main(){
int L,M;
scanf("%d %d", &L, &M);
int tmp = M / L;
int answer;
for(int i = 1; i * i <= tmp; i++){
if(tmp % i == 0 && checker(i, tmp/i) == 1){
answer = i;
}
}
cout<< answer * L << " " << tmp*L/answer<<endl;
}
3.2. 박인서 ¶
#include <iostream>
int gcd(int a, int b) {
while (a%b != 0) {
int t = a%b;
a = b;
b = t;
}
return b;
}
int main() {
int a, b;
std::cin >> a >> b;
int c = b / a, r = 1;
for (int i = 1; i*i <= c; i++)
if (i*(c / i) == c && gcd(i,c/i)==1) r = i;
std::cout << a*r << ' ' << a*c / r;
return 0;
}










