Problem 863
Count Integers With Even Digit Sum
Easy · 10 pts · Math
Problem
Count the positive integers from 1 to NUM whose digit sum is even. A loop works for small NUM. For a fast answer, notice that numbers alternate between even and odd digit sums within every group of ten, so the count is NUM / 2 if the digit sum of NUM is even and (NUM - 1) / 2 if it is odd, using integer division.
Input
A single integer NUM.
Output
Print how many integers from 1 to NUM have an even digit sum.
Constraints
1 <= NUM <= 10^9
Example input
30
Example output
14
Explanation
Up to 30, the numbers with an even digit sum are 2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26 and 28, so the answer is 14.