[백준5086_자바스크립트(javascript)] - 배수와 약수

경이·2024년 9월 28일

𝑩𝑶𝑱 (𝒋𝒔)

목록 보기
188/325

🔴 문제

배수와 약수


🟡 Sol

const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
const inputs = fs.readFileSync(path).toString().trim().split('\n');

for (const input of inputs) {
  const [a, b] = input.split(' ').map(Number);

  if (a == 0 && b == 0) break;

  if (a % b === 0) console.log('multiple');
  else if (b % a === 0) console.log('factor');
  else console.log('neither');
}

🟢 풀이

⏰ 소요한 시간 : -

입력받은 두 수를 파싱한 뒤 배열 디스트럭처링 할당을 통해 ab에 저장한다.
둘다 0이면 출력을 종료하고, 첫 번째 숫자가 두 번째 숫자의 약수일 경우엔 factor, 배수라면 multiple, 둘 다 아니라면 neither를 출력해주면 된다.


🔵 Ref

profile
록타르오가르

0개의 댓글