#P16641. [GKS 2018 #B] No Nine
[GKS 2018 #B] No Nine
Problem Description
No Nine is a counting game that you can try when you are bored. In this game, you are only allowed to say numbers that are legal. A number is legal if and only if all of the following are true:
- it is a natural number (i.e. in the set )
- it does not contain the digit anywhere in its base representation
- it is not divisible by
For example, the numbers and are legal. The numbers , , , and are not legal.
On the first turn of the game, you choose and say a legal number . On each subsequent turn, you say the next legal number. For example, if you played a game with , you would say , and so on.
Alice is very good at this game and never makes mistakes. She remembers that she played a game in which the first number was and the last number was (when she got tired of the game and stopped), and she wonders how many turns were in the game in total (that is, how many numbers she said).
Input Format
The input starts with one line containing one integer ; test cases follow. Each test case consists of a single line containing two integers and : the first and last numbers from the game, as described above.
Output Format
For each test case, output one line containing Case #x: y, where is the test case number (starting from ), and is the number of the turns played in the game.
2
16 26
88 102
Case #1: 9
Case #2: 4
Hint
In Sample Case #1, the game lasted for 9 turns, and the numbers Alice said were: .
In Sample Case #2, the game lasted for 4 turns, and the numbers Alice said were: .
Limits
.
does not contain a digit.
is not divisible by .
does not contain a digit.
is not divisible by .
Small dataset (Test set 1 - Visible)
.
Large dataset (Test set 2 - Hidden)
.