Pagini recente » Cod sursa (job #1163550) | Cod sursa (job #3205216) | Cod sursa (job #2468917) | Cod sursa (job #898563) | Cod sursa (job #1703285)
#include <cstdio>
#include <cstdlib>
using namespace std;
const int N = 1000000;
int i,x, K,A,B,C, ans=0;
inline int cifre(int x)
{
int cnt=0;
if(!C && !x) return 1;
while(x)
{
if(x%10==C) ++cnt;
x/=10;
}
return cnt;
}
int main()
{
freopen("cifre.in", "r", stdin);
freopen("cifre.out", "w", stdout);
scanf("%d%d%d%d", &A, &B, &C, &K);
ans=0;
if(B-A<N)
{
for(i=A; i<=B; ++i)
ans += (cifre(i)>=K);
long double z=(double)ans/(B-A+1);
printf("%.10Lf\n", z);
return 0;
}
for(i=1; i<=N; ++i)
{
x = A+rand()%(B-A+1);
if(cifre(x)>=K) ++ans;
}
long double z=(double)ans/N;
printf("%.10Lf\n", z);
return 0;
}