N개의 최소공배수

2020.07.31

const getGreatestCommonDivisor = (a, b) => {
  if (b) {
    const newA = b;
    const newB = a % b;
    return getGreatestCommonDivisor(newA, newB);
  }
  return a;
};

const getLowestCommonMultiple = (a, b) => {
  return (a * b) / getGreatestCommonDivisor(a, b);
};

const solution = (arr) => {
  return arr.reduce(getLowestCommonMultiple);
};
  • 유클리드 호제법 만세
    (소인수분해 노쓸모)

0개의 댓글