Subsets whose lexicographic order matches
Time limit8sMemory limit512 MB
Count non-empty subsets of the integers from A to B whose numeric order equals their lexicographic decimal order, modulo P.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Trie, Math
- Solved
- No attempts yet
Problem
Consider sets of natural numbers. In some sets, sorting the elements by value and sorting their decimal representations lexicographically give the same order. {2, 27, 3125, 9000} is such a set. {2, 27, 243} is not, because lexicographic sorting gives {2, 243, 27}.
Take the set of all integers from to inclusive and count the subsets that have this property. The empty set is not counted. The count can grow very large, so print it modulo , which is given in the input.
Input
The input holds several datasets. Each dataset is one line with three integers , , and separated by a space. They satisfy , , and .
A line holding three zeros marks the end of the input. Do not process that line.
Output
For each dataset, print the number of subsets modulo on its own line.