#P16872. [GKS 2022 #A] Interesting Integers

[GKS 2022 #A] Interesting Integers

Problem Description

Let us call an integer interesting if the product of its digits is divisible by the sum of its digits. You are given two integers AA and BB. Find the number of interesting integers between AA and BB (both inclusive).

Input Format

The first line of the input gives the number of test cases, TT. TT lines follow.

Each line represents a test case and contains two integers: AA and BB.

Output Format

For each test case, output one line containing Case #x\#x: yy, where xx is the test case number (starting from 11) and yy is the number of interesting integers between AA and BB (inclusive).

4
1 9
91 99
451 460
501 1000
Case #1: 9
Case #2: 0
Case #3: 5
Case #4: 176

Hint

In Sample Case #11, since the product and the sum of digits are the same for single-digit integers, all integers between 11 and 99 are interesting.

In Sample Case #22, there are no interesting integers between 9191 and 9999.

In Sample Case #33, there are 55 interesting integers between 451451 and 460460:

  1. 451451 (product of its digits is 4×5×1=204 \times 5 \times 1 = 20, sum of its digits is 4+5+1=104 + 5 + 1 = 10).

  2. 453453 (product of its digits is 4×5×3=604 \times 5 \times 3 = 60, sum of its digits is 4+5+3=124 + 5 + 3 = 12).

  3. 456456 (product of its digits is 4×5×6=1204 \times 5 \times 6 = 120, sum of its digits is 4+5+=154 + 5 + = 15).

  4. 459459 (product of its digits is 4×5×9=1804 \times 5 \times 9 = 180, sum of its digits is 4+5+9=184 + 5 + 9 = 18).

  5. 460460 (product of its digits is 4×6×0=04 \times 6 \times 0 = 0, sum of its digits is 4+6+0=104 + 6 + 0 = 10).

Limits

1T1001 \le T \le 100.

Test Set 11

1AB1051 \le A \le B \le 10^5.

Test Set 22

1AB10121 \le A \le B \le 10^{12}.