Pagini recente » Cod sursa (job #2458294) | Cod sursa (job #1690785) | Cod sursa (job #1981415) | Cod sursa (job #1428813) | Cod sursa (job #1505251)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cifre.in");
ofstream fout("cifre.out");
const int Lim = 1e5;
const int OpMax = 5e5;
int a, b, c, k;
inline bool Check(int x){
int digits = 0;
while(x){
digits += (x % 10 == c);
x /= 10;
}
return (digits >= k);
}
#define Random(a, b) (a + (rand() % (b - a + 1)))
inline float SolveB(){
int ways = 0;
for(int i = 1; i <= OpMax; i++){
ways += Check(Random(a, b));
}
return (1.0 * ways / OpMax);
}
inline float SolveA(){
int ways = 0;
for(int i = a; i <= b; i++){
ways += Check(i);
}
return (1.0 * ways / (b - a + 1));
}
int main(){
srand(time(NULL));
fin >> a >> b >> c >> k;
float answer = (b - a <= Lim) ? SolveA() : SolveB();
fout << answer;
return 0;
}