function greatestCommonDivisor(a, b) {return b ? greatestCommonDivisor(b, a % b) : Math.abs(a);}
function leastCommonMultipleOfTwo(a, b) {return (a * b) / greatestCommonDivisor(a, b);}
function gcdlcm(a, b) {
return [greatestCommonDivisor(a, b),leastCommonMultipleOfTwo(a, b)];
}
function gcd(a, b) {
if (a < b) {
let temp = a;
a = b;
b = a;
}
while (b !== 0) {
let n = a % b;
a = b;
b = n;
}
return a;
}
'Algorithm > 알고리즘 예제코드' 카테고리의 다른 글
소수판별 (0) | 2021.09.16 |
---|---|
Sort (0) | 2021.09.10 |
정규식 (0) | 2021.08.25 |
[알고리즘 예제][그래프탐색]BFS (0) | 2021.07.06 |
[알고리즘 예제][정렬]Q_sort. (0) | 2021.07.06 |