Pagini recente » Cod sursa (job #867359) | Cod sursa (job #1522989) | Cod sursa (job #1821136) | Cod sursa (job #2887256) | Cod sursa (job #912456)
Cod sursa(job #912456)
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;
ifstream fin("cifre.in");
ofstream fout("cifre.out");
const int xmax= 1000000000;
const int pl= 10000;// piece length, aprox. sqrt(xmax);
const int f[6]= {10000, 3439, 523, 36, 1, 0};
const int output_precision= 4;
int c_cnt(int x, int c){
int sol= 0;
while (x>0){
if (x%10==c){
++sol;
}
x/= 10;
}
return sol;
}
int main(){
int a, b, c, k;
fin>>a>>b>>c>>k;
int dif= b-a+1;
int sol= 0;
if (b-a+1>pl){
while (a%pl!=0){
if (c_cnt(a, c)>=k){
++sol;
}
++a;
}
while (b-a+1>pl){
int aux= k-c_cnt(a/pl, c);
if (aux<0){
aux= 0;
}else if (aux>5){
aux= 5;
}
sol+= f[aux];
a+= pl;
}
}
while (a<=b){
if (c_cnt(a, c)>=k){
++sol;
}
++a;
}
fout<<setprecision(output_precision)<<fixed;
fout<<(double)sol/dif<<"\n";
return 0;
}