[BJ / 10430] 나머지

Lainlnya·2023년 3월 31일
0

BaekJoon

목록 보기
16/37

문제

(A+B)%C는 ((A%C) + (B%C))%C 와 같을까?

(A×B)%C는 ((A%C) × (B%C))%C 와 같을까?

세 수 A, B, C가 주어졌을 때, 위의 네 가지 값을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000)

출력

첫째 줄에 (A+B)%C, 둘째 줄에 ((A%C) + (B%C))%C, 셋째 줄에 (A×B)%C, 넷째 줄에 ((A%C) × (B%C))%C를 출력한다.

예시

풀이

단순히 문제에 있는 풀이식을 출력하는 문제였다.

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
rl.on('line', (line) => {
  input = line.split(' ').map((el) => parseInt(el));
});

rl.on('close', () => {
  console.log(solution(input));
});

function solution(nums) {
  let answer = '';
  answer += ((nums[0] + nums[1]) % nums[2]) + '\n';
  answer += (((nums[0] % nums[2]) + (nums[1] % nums[2])) % nums[2]) + '\n';
  answer += ((nums[0] * nums[1]) % nums[2]) + '\n';
  answer += ((nums[0] % nums[2]) * (nums[1] % nums[2])) % nums[2];

  return answer;
}
profile
Growing up

0개의 댓글