This page is still under construction.

Parts of this page are still being built. What you see may change.

Interesting Integers

Time limit20sMemory limit1024 MB

Summary
Count the integers between A and B (inclusive) whose digit product is divisible by their digit sum.
Level

Medium6 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

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

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

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

Constraints

1≤T≤1001 \le T \le 100.

Hint

In Sample Case #1, 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 #2, there are no interesting integers between 9191 and 9999.

In Sample Case #3, there are five 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+6=154 + 5 + 6 = 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).

Examples1

  1. Example 1

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