#P1940. Reversible Number

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 10x10^x?

Problem Description

Some positive integers nn satisfy that in n+rev(n)n + \text{rev}(n) (where rev(n)\text{rev}(n) is the number obtained by reversing the decimal digits of nn), every digit of the sum is odd.

For example:

  • When n=36n = 36, 36+63=9936 + 63 = 99.
  • When n=409n = 409, 409+904=1313409 + 904 = 1313.

We call such nn Reversible numbers. Therefore, 3636, 6363, 409409, and 904904 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 10x10^x?

Input Format

A single positive integer xx.

Output Format

Output a single line containing one integer, the answer.

4

720

Hint

For 30%30\% of the testdata, the answer does not exceed 23212^{32} - 1.

For 100%100\% of the testdata, 3x4003 \le x \le 400.

Translated by ChatGPT 5