https://programmers.co.kr/learn/courses/30/lessons/12940
function solution(n, m) {
var answer = [];
var min = Math.min(n,m);
var gcd = 0; // greatest common divisor
// gcd
for(var i=min; i>0; i--){
if((m%i ===0) && (n%i ===0)){
gcd= i;
answer[0]=gcd;
break;
}
}
// lcm: least common multiple
answer[1]=(m/gcd)*(n/gcd)*gcd; //알고있는 지식으로 풀었음..
return answer;
}
var minNum = Math.min(n,m);
while(b!=0){
n=a%b;
a=b;
b=n;
} return a;
function solution(n, m) {
var answer = [];
var biggerNumber = Math.max(n,m);
var smallerNumber = Math.min(n,m);
// gcd
function calGcd(a,b) {
if (b === 0){
return a;
}
return calGcd(b, a%b)
}
var gcd = calGcd(biggerNumber,smallerNumber );
// lcm
var lcm = (m * n) / gcd;
answer[0] = gcd;
answer[1] = lcm;
return answer;
}
유클리드 호제법, 재귀함수