hdu4389

maksyuki 发表于 oj 分类,标签:
0

X mod f(x)

Problem Description

Here is a function f(x): int f ( int x ) { if ( x == 0 ) return 0; return f ( x / 10 ) + x % 10;} Now, you want to know, in a given interval [A, B] (1 <= A <= B <= 109), how many integer x that mod f(x) equal to 0.

Input

The first line has an integer T (1 <= T <= 50), indicate the number of test cases.
Each test case has two integers A, B.

Output

For each test case, output only one line containing the case number and an integer indicated the number of x.

Sample Input

2
1 10
11 20

Sample Output

Case 1: 10

Case 2: 3

Author

WHU

Source

2012 Multi-University Training Contest 9

 

题目类型:数位DP

算法分析:dp[pos][mod][d][sum]表示前i位数除以d得到余数mod且此时前i位和为sum的数字的个数,这里d在1~81范围内枚举,递归的边界是恰好满足d == sum且mod % sum == 0,最后累加所有的情况即可(枚举d)