#K85342. Equal Subset Partition of Consecutive Integers
Equal Subset Partition of Consecutive Integers
Equal Subset Partition of Consecutive Integers
Given a positive integer n, consider the set of the first n positive integers \(\{1, 2, \dots, n\}\). Your task is to determine whether it is possible to partition these numbers into two subsets such that the sum of the numbers in each subset is equal.
Let \(S\) be the sum of all the numbers, i.e., \[ S = 1 + 2 + \cdots + n = \frac{n(n+1)}{2}. \]
A necessary (and sufficient) condition for such a partition to exist is that the sum \(S\) is even. In other words, if \(\frac{n(n+1)}{2}\) is even, output YES
, otherwise output NO
.
Note: The input is read from standard input and the output should be printed to standard output.
inputFormat
The input consists of a single line that contains one integer \(n\) (1 ≤ n ≤ 107).
outputFormat
Output YES
if it is possible to partition the set \(\{1, 2, \dots, n\}\) into two subsets with equal sum; otherwise, output NO
.
5
NO
</p>