Interesting Integers
Time limit20sMemory limit1024 MB
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 and . Find the number of interesting integers between and (both inclusive).
Input
The first line of the input gives the number of test cases, . lines follow. Each line represents a test case and contains two integers: and .
Output
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the number of interesting integers between and (inclusive).
Constraints
.
Hint
In Sample Case #1, since the product and the sum of digits are the same for single-digit integers, all integers between and are interesting.
In Sample Case #2, there are no interesting integers between and .
In Sample Case #3, there are five interesting integers between and :
- (product of its digits is , sum of its digits is ).
- (product of its digits is , sum of its digits is ).
- (product of its digits is , sum of its digits is ).
- (product of its digits is , sum of its digits is ).
- (product of its digits is , sum of its digits is ).