Rainbow Numbers
Time limit1sMemory limit512 MB
Count integers between two huge bounds (up to 100000 digits) whose decimal digits never repeat consecutively, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Define a rainbow number as an integer that, when written in base with no leading zeros, has no two adjacent digits equal.
Given a lower bound and an upper bound, count the rainbow numbers between them, inclusive.
Input
The first line contains a single integer (), the lower bound.
The second line contains a single integer (), the upper bound.
It is guaranteed that . The bounds are not a misprint; and can have up to digits.
Output
Print a single integer, the number of rainbow numbers between and inclusive. This number can be very large, so print it modulo .