logo AlgoBeat OnlineJudge
登录 注册

#216664. [GKS 2018 #B] No Nine

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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).

输入格式

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.

输出格式

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.

样例

样例输入 1

2
16 26
88 102

样例输出 1

Case #1: 9
Case #2: 4

数据范围与提示

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)

.