Numbers
Time limit1sMemory limit512 MB
Given n up to 10^18, count the ordered pairs of palindromes (a, b) whose sum is n.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Math, Brute force
- Solved
- No attempts yet
Input
A palindrome is an integer which reads the same backward as forward. For example, numbers 142241 and 102201 are palindromes, but 1023401 and 10510 are not. You want to represent a number as the sum of two palindromes. Find the number of ways to do it.
Input
There is only one line containing the integer ().
Output
Output one number, the number of ways to represent the number as the sum of two palindromes.
Hint
In the first test, the following pairs of numbers are suitable: , , , .
In the second test, the following pairs of numbers are suitable: , , , .
In the third test, the following pairs of numbers are suitable: , , , , , .