Description
As we know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers Are not the "palindrome numbers in decimal form,but", "Base,they". Become number. Like 288,it ' s not a palindrome number under 10-base. But If we convert it to 17-base number,it ' s Gg,which becomes a palindrome number. So we define a interesting function f (n,k) as follow:
F (n,k) =k if n is a palindrome number under K-base.
Otherwise f (n,k) =1.
Now given your 4 integers l,r,l,r,you need to caluclate the mathematics expression∑ri=l∑rj=lf (i,j) \sum_{i=l}^{r}\sum_{j=l }^{r}f (I,J).
When representing the K-base (k>10) Number,we need to-represent 10,b to represent . The biggest number is Z (a), so we are only discuss about the situation at most 36-base number.
Input
The ' the ' of ' a integer T,which denotes the number of test cases.
In the following T Lines,each line consists of 4 integers l,r,l,r.
(1≤t≤105,1≤l≤r≤109,2≤l≤r≤36) (1≤t≤10^5,1≤l≤r≤10^9,2≤l≤r≤36)
Output
For each test case, output the answer in the form of ' case #i: ans ' in a seperate line.
Sample Input
3
1 1 2
1 982180 496690841 524639270 5
20
Sample Output
Case #1:665 case
#2:1000000 case
#3:447525746
the
The contribution of L to r and whether it is the palindrome number in the L to the R system.
train of Thought
the number of palindrome numbers is actually a regular, assuming the K-K system:
1 1-digit palindrome number: K1−k0 k^1-k^0
2 2-digit palindrome number: K1−k0 k^1-k^0
3 3-digit palindrome number: K2−k1 k^2-k^1
4 4-digit palindrome number: K2−k1 k^2-k^1
5 5-digit palindrome number: K3−k2 k^3-k^2
...
So we can consider enumerating into [l,r] [l,r] to calculate how many palindrome numbers there are between [1,r] [1,r] and [1,l−1] [1,l-1].
For each system K K