#C5159. Count Distinct Pairs With Even Sum
Count Distinct Pairs With Even Sum
Count Distinct Pairs With Even Sum
Given a positive integer \(n\), compute the total number of distinct pairs \((i, j)\) such that \(1 \leq i < j \leq n\) and \(i+j\) is even.
A pair \((i, j)\) is considered distinct if \(i < j\). Notice that the sum of two odd numbers or two even numbers is even. Therefore, the problem can be solved by counting the number of pairs from odd numbers and even numbers separately.
If there are \(odd\) odd numbers and \(even\) even numbers between 1 and \(n\), the number of ways to choose 2 odd numbers is given by:
\(\displaystyle \frac{odd \times (odd - 1)}{2}\)
Similarly, the number of ways to choose 2 even numbers is:
\(\displaystyle \frac{even \times (even - 1)}{2}\)
The answer is the sum of these two values.
inputFormat
The input consists of a single line containing a positive integer \(n\).
outputFormat
Output a single integer representing the total number of distinct pairs \((i,j)\) with an even sum.
## sample1
0
</p>