#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream in("cifre.in");
ofstream out("cifre.out");
const int LIM = 1e4;
int i, x, k, a, b, c, res;
int power[]={1, 9, 81, 729, 6561};
int comb[10][10];
int get_digits(int x) {
int cnt=0;
if(c == 0 && x == 0)
return 1;
while(x != 0) {
if(x % 10 == c)
cnt++;
x /= 10;
}
return cnt;
}
int main()
{
in >> a >> b >> c >> k;
comb[4][0] = 1;
comb[4][1] = 4;
comb[4][2] = 6;
comb[4][3] = 4;
comb[4][4] = 1;
int i;
for(i = a; (i % LIM != 0 || i < LIM) && i <= b; i++)
if(k <= get_digits(i))
res ++;
while(i + LIM <= b) {
x = max(k - get_digits(i / LIM), 0);
while(x<=4) {
res += comb[4][x] * power[4 - x];
x++;
}
i += LIM;
}
while(i <= b) {
if(k <= get_digits(i))
res++;
i++;
}
double sol = (double)res / (b - a + 1);
out << setprecision(10) << fixed;
out << sol << '\n';
in.close();
out.close();
return 0;
}