A newly commissioned office tower numbers its floors 1 through n in the usual way. Building management runs a quarterly walkthrough that only visits floors whose floor number has an even digit sum — for instance, floor 26 qualifies (2+6=8, even) while floor 23 does not (2+3=5, odd). Given the top floor number n, report how many of the floors numbered 1 through n qualify for the walkthrough.
A single line containing one integer n, the highest floor number in the tower.
Print a single integer: the count of floors in [1, n] whose digit sum is even.
Example 1
Input
30
Expected
14
Explanation
Checking every floor from 1 to 30, the floors with an even digit sum are 2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, 28 — 14 floors in total. Floor 30 itself has digit sum 3+0=3, which is odd, so it is not counted.
Example 2
Input
1
Expected
0
Explanation
The only floor is floor 1, whose digit sum is 1, which is odd. So no floor qualifies and the answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →