P1940 Reversible Number

Background

This problem is adapted from Project Euler Problem 145: > Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n). > > There are 120 reversible numbers below one-thousand. > > How many reversible numbers are there below $10^x$?

Description

Some positive integers $n$ satisfy that in $n + \text{rev}(n)$ (where $\text{rev}(n)$ is the number obtained by reversing the decimal digits of $n$), every digit of the sum is odd. For example: - When $n = 36$, $36 + 63 = 99$. - When $n = 409$, $409 + 904 = 1313$. We call such $n$ Reversible numbers. Therefore, $36$, $63$, $409$, and $904$ are all Reversible numbers. Numbers with leading zeros are not considered Reversible numbers. How many Reversible numbers are there that are less than or equal to $10^x$?

Input Format

A single positive integer $x$.

Output Format

Output a single line containing one integer, the answer.

Explanation/Hint

For $30\%$ of the testdata, the answer does not exceed $2^{32} - 1$. For $100\%$ of the testdata, $3 \le x \le 400$. Translated by ChatGPT 5