#define LOCAL #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template ostream& operator <<(ostream& out, const pair& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template ostream& operator <<(ostream& out, const array& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template ostream& operator <<(ostream& out, const vector& a) { out << "["; bool first = true; for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template ostream& operator <<(ostream& out, const set& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template ostream& operator <<(ostream& out, const map& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } template auto vect(const T& v, int n) { return vector(n, v); } template auto vect(const T& v, int n, D... m) { return vector(n, vect(v, m...)); } typedef long long int64; typedef pair ii; #define SZ(x) (int)((x).size()) template static constexpr T inf = numeric_limits::max() / 2; const int MOD = 1e9 + 7; // const int MOD = 998244353; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } // mt19937_64 mrand(random_device{}()); // int64 rnd(int64 x) { return mrand() % x; } template void out(const vector& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; } template bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template void dedup(vector& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } void add(int& x, int y) { x += y; if (x >= MOD) x -= MOD; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; const int R = 1e6 + 10; const int C = 1e4 + 10; struct BIT{ int n; vector val; BIT(int _n): n(_n), val(_n + 1, 0) {} void add(int i, int x) { for(++i; i <= n; i += i & -i) val[i] += x;} int sum(int i) { int ret = 0; for(++i; i; i -= i & -i) ret += val[i]; return ret; } }; bitset isp; vector ps, cs; void init(int n) { ps.clear(); cs.clear(); isp[0] = isp[1] = 1; for (int p = 2; p * p <= R; ++p) { if (!isp[p]) { for (int q = p * p; q <= R; q += p) isp[q] = 1; } } for (int i = 2; i <= R; ++i) { if (!isp[i]) { ps.push_back(i); if (i <= n) cs.push_back(i); } } } int64 phi(int64 x, int64 a, int64 cnt) { int64 ret = 0; vector mu(a + 1, 1), minp(a + 1, a); for (int i = 1; i <= a; ++i) { if (!isp[i]) { for (int64 j = i; j <= a; j += i) { mu[j] *= -1; ckmin(minp[j], i); } for (int64 j = i * i, k = j; k <= a; k += j) mu[k] = 0; } ret += mu[i] * (x / i); } vector sum(cnt, 0); for (int64 low = 1; low < x / a; low += a) { int64 high = min(low + a, x / a); BIT bit(a); bitset is_one; for (int b = 0; b < cnt; ++b) { int p = cs[b], mn = max(x / p / high, a / p), mx = min(x / p / low, a); if (p < mx) { for (int m = mx; m > mn; --m) { if (mu[m] && minp[m] > p) { ret -= mu[m] * (sum[b] + x / p / m - low + 1 - bit.sum(x / p / m - low)); } } } sum[b] += a - bit.sum(a - 1); for (int q = (p - low % p) % p; q < a; q += p) { if (!is_one[q]) { bit.add(q, 1); is_one[q] = 1; } } } } return ret; } int64 pi(int64 x) { int r = sqrt(1.0 * x), c = cbrt(x); init(c); if (x <= R) return upper_bound(ps.begin(), ps.end(), x) - ps.begin(); int64 a = upper_bound(ps.begin(), ps.end(), c) - ps.begin(), b = upper_bound(ps.begin(), ps.end(), r) - ps.begin(); int64 ret = phi(x, c, a) + (b + a - 2) * (b - a + 1) / 2; int idx = b - 1; for (int s = r; s <= x && idx >= a; s += c) { vector cur(c + 1); bitset val; val.flip(); cur[0] = b; for (int p : cs) { for (int q = (p - s % p) % p; q <= c; q += p) val[q] = 0; } for (int i = 1; i <= c; ++i) cur[i] = cur[i - 1] + val[i]; b = cur[c]; while (s <= x / ps[idx] && x / ps[idx] < s + c && idx >= a) { ret -= cur[x / ps[idx] - s]; --idx; } } return ret; } int main() { int64 L, R; cin >> L >> R; int64 ret = pi(R) - pi(L - 1); ret += pi(2 * R - 1) - pi(2 * L); cout << ret << '\n'; return 0; }