42. Sum of Even and Odd Numbers
Foundation1000 ms256 MBSolved by 0%
Read an integer n and print two values on one line, separated by a space:
the sum of all even numbers from 1 to n, then the sum of all odd numbers from 1 to n.
Constraints - `1 ≤ n ≤ 1000000`
Input
A single line containing one integer n.
Output
Print two integers on one line, separated by a single space — the sum of the evens, then the sum of the odds.
Input10
Output30 25
Noteis a small case you can check by hand
Input1
Output0 1
Noteis the smallest input, where there are no even numbers at all
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution