#include #define FASTIO using namespace std; using ll = long long; using Vi = vector; using Vl = vector; using Pii = pair; using Pll = pair; constexpr int I_INF = numeric_limits::max(); constexpr ll L_INF = numeric_limits::max(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% class UnionFind { using i64 = std::int64_t; private: std::vector par; std::vector sz; public: UnionFind(i64 N) : par(N), sz(N, 1) { for (i64 i = 0; i < N; ++i) par[i] = i; } i64 root(i64 x) { return par[x] == x ? x : par[x] = root(par[x]); } bool same(i64 x, i64 y) { return root(x) == root(y); } void unite(i64 x, i64 y) { x = root(x); y = root(y); if (x == y) return; if (sz[x] < sz[y]) std::swap(x, y); par[y] = x; sz[x] += sz[y]; } i64 size(i64 x) { return sz[root(x)]; } void reset(i64 N) { par.resize(N); for (i64 i = 0; i < N; ++i) par[i] = i; sz.assign(N, 1); } }; void solve() { ll L, R; cin >> L >> R; UnionFind uf(R - L + 1); for (ll i = L; i <= R; i++) { for (ll j = 2 * i; j <= R; j += i) { uf.unite(i - L, j - L); } } unordered_set st; for (ll i = 0; i < R - L + 1; i++) { st.emplace(uf.root(i)); } cout << (ll)st.size() - 1 << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); #endif #ifdef FILEINPUT ifstream ifs("./in_out/input.txt"); cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT ofstream ofs("./in_out/output.txt"); cout.rdbuf(ofs.rdbuf()); #endif solve(); cout << flush; return 0; }