Counting problem

Accepts: 3
Submissions: 61
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Supose that n has L digits, we used $d_0, d_1, d_2, \ldots, d_{L-1}$ to indicate every digit of n from least significant digit to most significant one. $f(n, k) = \sum\limits_{i=0}^{L-1}d_i^k$, for example $f(305, 2) = 5^2 + 3^2 + 0^2 = 34$ We are curious about that for each x ranged from a to b($a \leq b$), how many integers make $S=f(x, k)$ (here S is a constant) true.
Input
Multi test cases (about 100), every case gives four integers a, b, k, S in a single line. Please process to the end of file. [Technical Specification] $1 \leq a \leq b \leq 999999999$ $1 \leq k \leq 15$ $1 \leq S \leq 10^{16}$
Output
For each case£Ĵoutput a number in a single line indicates how many x ranged from a to b makes $S=f(x, k)$ true.
Sample Input
1 1 1 1
1 10 2 1
Sample Output
1
2