https://www.acmicpc.net/problem/18005
18005번: Even or Odd?
Output 2 if the sum of any n consecutive integers in the range from 1 to 1018 must be even, 1 if the sum must be odd, or 0 if the sum could be either even or odd.
www.acmicpc.net
문제
Your friend has secretly picked n consecutive positive integers between 1 and 1018 and wants you to guess if their sum is even or odd.
If the sum must be even, write 2. If the sum must be odd, write 1. If the sum could be even or could be odd, write 0.
입력
The single line of input contains a single integer n (1 ≤ n ≤ 109).
출력
Output 2 if the sum of any n consecutive integers in the range from 1 to 1018 must be even, 1 if the sum must be odd, or 0 if the sum could be either even or odd.
예제 입력 1
3
예제 출력 1
0
예제 입력 2
6
예제 출력 2
1
예제 입력 3
12
예제 출력 3
2
코드
const N = Number(require('fs').readFileSync('/dev/stdin').toString());
let result = 0;
if(N % 2 === 0){
result = N / 2 % 2 === 1 ? 1 : 2;
}
console.log(result);'알고리즘 > 백준' 카테고리의 다른 글
| [백준] 2501: 약수 구하기 / Node.js (JavaScript) (0) | 2023.04.01 |
|---|---|
| [백준] 15633: Fan Death / Node.js (JavaScript) (0) | 2023.04.01 |
| [백준] 10610: 30 / Node.js (JavaScript) (0) | 2023.03.29 |
| [백준] 24736: Football Scoring / Node.js (JavaScript) (0) | 2023.03.28 |
| [백준] 24568: Cupcake Party / Node.js (JavaScript) (0) | 2023.03.27 |
댓글