Problem C
Heir's Dilemma
Your favorite uncle has passed away, leaving you a large
estate. Bank account numbers, locations of safe deposit boxes,
and GPS coordinates to buried treasures are all locked in an
electronic safe in your uncle’s office behind a picture of dogs
playing poker. One day he showed you the safe with its
The combination is a sequence of six decimal digits. If an incorrect combination is entered the safe enforces a thirty-second delay before accepting another combination. So a brute-force effort to try all six-digit combinations could take months.
Your uncle had planned to give you, his sole heir, the combination one day, but due to an unfortunate hang-gliding accident in Kansas, you now must rely on your deductive and programming skills to access the key to your inheritance.
Here’s what you know:
-
The combination
is a sequence of six non-zero decimal digits. -
Your mother recalls that she heard your uncle mention that all the digits are different.
-
You remember that your uncle once said that the six digit number was divisible by each of its individual digits.
An example satisfying these conditions is
Even with the helpful data, it could take a while to get to open the safe, so the task is likely to be split into several sessions with separate ranges being tested. How many combinations are there to try in the range given?
Input
The input is a line with two space-separated integers
Output
Print one integer, the total number of possible combinations
to the safe, where each combination
Sample Input 1 | Sample Output 1 |
---|---|
123864 123865 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
198765 198769 |
0 |
Sample Input 3 | Sample Output 3 |
---|---|
200000 300000 |
31 |