[백준] Even or Odd? (18005)(kotlin)
문제 설명
입력 및 출력
» 입력
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.
예제 입출력
입력 | 출력 |
---|---|
3 | 0 |
6 | 1 |
12 | 2 |
문제 풀이1
fun main(args: Array<String>) = println(
readLine()!!
.toInt()
.let {
when {
it % 2 == 1 -> 0
(it + 1) % 2 == 1 && (it / 2) % 2 == 1 -> 1
else -> 2
}
}
)