Pagini recente » Profil M@2Te4i | Istoria paginii utilizator/mangelian | Istoria paginii utilizator/adi.florescu | Istoria paginii utilizator/antonia20032604 | Cod sursa (job #2091264)
#include <bits/stdc++.h>
int D(int n, int c, int k){
if(n < 10){
if(k > 1) return 0;
else if(k == 1){
if(n >= c) return 1;
return 0;
}
else return n + 1;
}
int cn = n, p10 = 1;
while(cn > 0){
p10 *= 10;
cn /= 10;
}
p10 /= 10;
int lastcif = n / p10;
int ans = 0;
if(c != 0){
if(lastcif == c)
ans += D(n % p10, c, k - 1);
else
ans += D(n % p10, c, k);
lastcif--;
if(lastcif < c)
ans += (lastcif + 1) * D(p10 - 1, c, k);
else
ans += lastcif * D(p10 - 1, c, k) + D(p10 - 1, c, k - 1);
return ans;
}
else{
cn = n;
int ncif1 = 0;
while(cn > 0){
ncif1++;
cn /= 10;
}
cn = n % p10;
int ncif2 = 0;
while(cn > 0){
ncif2++;
cn /= 10;
}
ans += D(n % p10, c, k - (ncif1 - ncif2 - 1));
ans += lastcif * D(p10 - 1, c, k);
return ans;
}
}
int main(){
FILE*fi,*fo;
fi=fopen("cifre.in","r");
fo=fopen("cifre.out","w");
int a, b, c, k;
fscanf(fi,"%d%d%d%d", &a, &b, &c, &k);
fprintf(fo,"%lf", (1.0 * D(b, c, k) - 1.0 * D(a - 1, c, k)) / (1.0 * b - 1.0 * a + 1));
fclose(fi);
fclose(fo);
return 0;
}