P1831 Lever Numbers
Description
If we take one digit of a number as the fulcrum, and the sum of the moments of the digits to the left about this point equals the sum of the moments of the digits to the right about this point, then the number is called a lever number.
For example, $4139$ is a lever number. Taking $3$ as the fulcrum, we have the equation: $4 \times 2 + 1 \times 1 = 9 \times 1$.
Given the interval $[x,y]$, find how many lever numbers are in $[x,y]$.
Input Format
Two integers, $x,y$.
Output Format
A single integer, the number of lever numbers in the interval $[x,y]$.
Explanation/Hint
Constraints
- For $40\%$ of the testdata, $x \le y \le x + 10^5$.
- For $100\%$ of the testdata, $1 \le x \le y \le 10^{18}$.
Translated by ChatGPT 5