사랑하애오

솔루션

const solution = (a, b) => {
  const getGCD = (a, b) => {
    let gcd = 1;
    for (let i = 1; i <= Math.min(a, b); i++) {
      if (a % i === 0 && b % i === 0) gcd = i;
    }
    return gcd;
  };

  const getPrimeFactors = (num) => {
    let pFactors = [];
    for (let i = 2; i <= Math.sqrt(num); i++) {
      while (num % i === 0) {
        pFactors = [...pFactors, i];
        num /= i;
      }
    }
    if (num > 2) pFactors = [...pFactors, num];
    return pFactors;
  };

  const answer = getPrimeFactors(b / getGCD(a, b)).find(
    (n) => n !== 2 && n !== 5
  )
    ? 2
    : 1;
  console.log(answer);

  return answer;
};

 

profile

사랑하애오

@사랑하애

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!