#C2751. Sum of Even Numbers
Sum of Even Numbers
Sum of Even Numbers
This problem requires you to compute the sum of all even numbers in the range from 1 to n (inclusive). If n is less than 1, then the sum should be 0.
You are given a single integer n as the input and you should output the sum of all even numbers between 1 and n. The solution must work correctly for negative values and zero.
The formula for the sum of even numbers can be derived, but you may use iterative or formula-based approaches.
Examples:
- For n = 10, the even numbers are 2, 4, 6, 8, 10 and their sum is 30.
- For n = 5, the even numbers are 2 and 4 with a sum of 6.
- For n = -4 or n = 0, the output is 0.
inputFormat
The input consists of a single integer n provided via standard input.
outputFormat
Output a single integer which is the sum of all even numbers from 1 to n.
## sample10
30