2132 - Self-divisible Numbers   

Description

An integer number is said to be self-divisible if each digit divides the number formed by all digits up to and including that digit evenly. If you find yourself puzzled by the previous sentence, you should not worry. You are not alone. I needed to scribble few examples to understand it myself.

Here are few of them:

1)
        213 is a self-divisible number because

        2 divides 2, 1 divides 21, and 3 divides 213.

2)
        201 is not a self-divisible number because

        2 divides 2, but 0 does not divide any number.

3)
        2534 is not a self-divisible number because

2 divides 2, 5 divides 25, but 3 does not divide 253.

Your task is to write a program to count the number of self-divisible numbers in a selected range. As an example, for the range of integers between 7 and 15, where

  • 7, 8, 9, 11, 12, and 15 are self-divisible
  • 10 is not self-divisible because it contains a zero, which cannot divide any number, and
  • 13 and 14 are not self-divisible because the 2nd digit in each number does not divide it.

your program must calculate a count of 6.

 

Input

Input to this problem starts with an integer N that represents the number of cases, N > 0 , on a separate line followed by a description of the N cases. Each case is described on a separate line by two positive integers S and F , where S is less than or equal to F , that represent the start and finish values of a range of integers. The two numbers are separated by a single blank space as shown in the Sample Input below. Each of the integers S and F consists of K digits, 0 < K < 400 , and the number of self-divisible numbers in the range between each pair is less than 1000000.

Output

For each case, the output consists of one line. The line starts with the case number starting with the value of one (1), followed by a ``:", as shown in the Sample Output below, and then followed by the number of self-divisible numbers in the range.

Sample Input  Download

Sample Output  Download

Tags




Discuss