# [Algorithm/JS] ๋ฐฑ์ค€ 10430๋ฒˆ ๋‚˜๋จธ์ง€

๐Ÿ”— ๋ฌธ์ œ ๋ฐ”๋กœ๊ฐ€๊ธฐ (opens new window)

# Question

(A+B)%C๋Š” ((A%C) + (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

(Aร—B)%C๋Š” ((A%C) ร— (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

์„ธ ์ˆ˜ A, B, C๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์œ„์˜ ๋„ค ๊ฐ€์ง€ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

# Input

์ฒซ์งธ ์ค„์— A, B, C๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (2 โ‰ค A, B, C โ‰ค 10000)

# Output

์ฒซ์งธ ์ค„์— (A+B)%C, ๋‘˜์งธ ์ค„์— ((A%C) + (B%C))%C, ์…‹์งธ ์ค„์— (Aร—B)%C, ๋„ท์งธ ์ค„์— ((A%C) ร— (B%C))%C๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

# Example Input

5 8 4
1

# Example Output

1
1
0
0
1
2
3
4

# Solution

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split(' ').map(Number);
const [a, b, c] = input;
console.log((a + b) % c);
console.log(((a % c) + (b % c)) % c);
console.log((a * b) % c);
console.log(((a % c) * (b % c)) % c);
1
2
3
4
5
6
7
Last Updated: 2022. 6. 5. ์˜คํ›„ 3:42:39