Problem 771
Sum of Even Numbers up to N
Problem
Print the sum of all even numbers from 1 to N: 2 + 4 + 6 + ... up to the largest even number not greater than N. A simple loop works for small N, but N can be a billion, so use the formula instead: with K = floor(N / 2) even numbers, the sum is 2 × (1 + 2 + ... + K) = K × (K + 1). The result needs a 64-bit integer.
Input
A single integer N.
Output
Print the sum of the even numbers from 1 to N.
Constraints
1 <= N <= 10^9
Example input
10
Example output
30
Explanation
For N = 10 the even numbers are 2, 4, 6, 8 and 10, and their sum is 30. The formula agrees: K = 5 and 5 × 6 = 30.