Mirror Numbers
Time limit1sMemory limit64 MB
Count how many numbers between A and B (up to 10^18) read the same when reflected in a mirror, using only digits 0,1,2,5,8 with 2 and 5 swapped.
- Level
Medium6 of 10
- Topics
- Combinatorics, String, Math, Brute force
- Solved
- No attempts yet
Problem
Digits on a digital display are shown by turning strokes on and off, like the numbers on an elevator display.
A number is called a mirror number if, when reflected in a mirror, it still reads as the original number. Under reflection, 0, 1, and 8 remain themselves, while 2 and 5 turn into each other. All other digits do not appear as valid digits. Therefore a mirror number can use only 0, 1, 2, 5, and 8, and the digits must match from both ends under this reflection rule.
For instance, 0, 101, and 1521 are mirror numbers, while 1221 and 1010 are not.




Given two integers A and B, write a program that prints how many mirror numbers are between A and B, inclusive.
Input
The first line contains two integers A and B separated by a space.
Output
Print the number of mirror numbers between A and B, inclusive.
Constraints
- 0 <= A <= B <= 10^18