Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- int main() {
- //#ifdef LOCAL
- // freopen("in.txt", "r", stdin);
- //#else
- // freopen("pnumber.inp", "r", stdin);
- // freopen("pnumber.out", "w", stdout);
- //#endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int L, R; cin >> L >> R;
- vector<bool> isPrime(R - L + 1, true);
- if (1 >= L) isPrime[1 - L] = false; // Xét riêng trường hợp số 1
- for (ll i = 2; i * i <= R; ++i)
- for (ll j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)
- isPrime[j - L] = false;
- for (ll x = L; x <= R; ++x)
- if (isPrime[x - L])
- cout << x << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment