๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/12940https://school.programmers.co.kr/learn/courses/30/lessons/131128
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function gcdlcm(a, b) {
var gcd = function(b, a) {
var r = (b % a);
return (r) ? gcd(a, r) : a;
}
return [gcd(b, a), ((b * a) / gcd(b, a))];
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(n, m) {
var answer = [];
let maxNumber=Math.max(n,m)
let minNumber=Math.min(n,m)
for(let i=minNumber; i>=1; --i){
if(n%i===0&&m%i===0){
answer.push(i)
break;
}
}
let refNum = maxNumber
while(answer.length===1){
if(refNum%n===0&&refNum%m===0){
answer.push(refNum)
break;
}
++refNum;
}
return answer;
}
๋๋์ ๐ฝ
๋๋ฌด ์๊ฐ์ํ๊ณ ํ์ด์ ๊ธธ๊ฒ ์ฝ๋๊ฐ ๋ฝํ๋ค
์ต๋ ๊ณต๋ฐฐ์๊ฐ ๋์์๊ณฑ/์ต๋๊ณต์ฝ์ ์์ ์ด์ฉํ์ผ๋ฉด ์ฐธ ์งง๊ฒ ๋๋ฌ์ํ
๋ฐ ์์ฝ๋ค๐ค