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
| #include <bits/stdc++.h> #define ll long long using namespace std;
const int N = 1e4 + 66;
ll a, b, res, num[N], nam[N]; int cnt, vis[N];
inline void pres_dou(int now, ll sum) { if (sum > b) return; if (sum != 0) num[++ cnt] = sum; if (now > 10) return; pres_dou(now + 1, sum * 10 + 6), pres_dou(now + 1, sum * 10 + 8); return; }
inline void yhm_cut() { int i, j, ret(0); for (i = 1; i <= cnt; ++ i) { if (vis[i]) continue; if (num[i] <= b / 2) nam[++ ret] = num[i]; else res += b / num[i] - a / num[i]; for (j = i + 1; j <= cnt; ++ j) if (num[j] % num[i] == 0) vis[j] = 1; } return (void)(cnt = ret); }
inline int cmp(int x, int y) {return x > y;}
inline void dfs(int now, ll sum, int t) { if (sum > b) return; if (now > cnt) return (void)((sum == 1) ? a = a : (res += (b / sum - a / sum) * ((t & 1) ? 1 : -1))); dfs(now + 1, sum, t); ll tmp = nam[now] / __gcd(nam[now], sum); if (tmp * sum <= b) dfs(now + 1, tmp * sum, t + 1); return; }
signed main() { a = read(), b = read(), -- a; pres_dou(1, 0), sort(num + 1, num + 1 + cnt); yhm_cut(), sort(nam + 1, nam + 1 + cnt, cmp); dfs(1, 1, 0), put(res);
return 0; }
|