백준 3036 링 Node.JS

0

Problem Solving

목록 보기
47/49
post-thumbnail

문제

https://www.acmicpc.net/problem/3036

풀이

최대공약수를 구해서 두 수를 나눈 결과물을 출력하면 되는 문제였다.

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");
const [first, ...others] = input[1].split(" ").map(Number);

function getGCD(a, b) {
    if (a % b === 0) return b;
    return getGCD(b, a % b);
}

const answer = new Array();
others.forEach((e) => {
    const GCD = getGCD(first, e);
    answer.push(`${first / GCD}/${e / GCD}`);
});
console.log(answer.join("\n"));

0개의 댓글