1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include <bits/stdc++.h> #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define pb push_back #define double long double #define int long long using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int>PII; const double eps = 1e-8; const int maxn = 200000 + 5; const int inf = 0x3f3f3f3f; const int mod = 1e9+7;
vector<int> vec;
void init(int now){ vec.push_back(now*10 + 4); vec.push_back(now*10 + 7); if(now < 100000000) init(now*10 + 4); if(now < 100000000) init(now*10 + 7); }
int bitada(int l,int r,int x){ if(x <= l){ return r - l+1; } if(x > r){ return 0; } return r - x+1; }
int bitaxiao(int l,int r,int x){ if(x >= r){ return r - l +1; } if(x < l) return 0; return x - l+1; }
signed main(){
vec.push_back(-1); init(0); sort(vec.begin(),vec.end()); int pl,pr,vl,vr,k; cin >> pl >> pr >> vl >> vr >> k; double ans = 0; double r = (pr-pl+1)*(vr-vl+1); for(int i=1;i<=vec.size()-k;i++){ int minn = vec[i]; int maxx = vec[i+k-1]; int minn2 = vec[i-1]; int maxx2 = vec[i+k]; if(bitada(pl,pr,maxx) == 0 && bitada(vl,vr,maxx) == 0) break; ans += (bitada(pl,pr,maxx)-bitada(pl,pr,maxx2))*(bitaxiao(vl,vr,minn)-bitaxiao(vl,vr,minn2)); ans += (bitada(vl,vr,maxx)-bitada(vl,vr,maxx2))*(bitaxiao(pl,pr,minn)-bitaxiao(pl,pr,minn2)); if(k == 1 && pl <= minn && pr >= minn && vl <= minn && vr >= minn) ans--; } printf("%.12Lf\n",ans/r); return 0; }
|