Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #pragma GCC target("tune=native")
- #pragma GCC optimize("fast-math,unroll-loops")
- #include <math.h>
- #include <algorithm>
- #include <set>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <string>
- #include <time.h>
- #include <cassert>
- #include <functional>
- #include <memory.h>
- #include <stack>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <random>
- #include <chrono>
- #include <complex>
- #include <fstream>
- #include <climits>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef unsigned u;
- typedef long double ld;
- typedef vector<vector<int>> vvi;
- typedef unsigned char uc;
- typedef unsigned short us;
- typedef complex<double> cd;
- #define INF 1000000000
- #define LLINF 1000000000000000000LL
- #define EPS 1e-9l
- #define pii pair<int, int>
- const int DEBUG = 0;
- #ifdef LOCAL
- mt19937 gen(228);
- #else
- mt19937 gen((u)chrono::high_resolution_clock::now().time_since_epoch().count());
- #endif
- #pragma comment(linker, "/STACK:76777216")
- vector<int> sieve(int n)
- {
- vector<char> a(n + 1, 0);
- for (int i = 2; i * i <= n; i++)
- {
- for (int j = i * i; j <= n && !a[i]; j += i)
- {
- a[j] = 1;
- }
- }
- vector<int> prime;
- for (int i = 2; i <= n; i++)
- {
- if (!a[i])
- {
- prime.push_back(i);
- }
- }
- return prime;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.setf(cout.fixed);
- cout.precision(12);
- auto START_TIME = chrono::high_resolution_clock::now();
- ll a, b;
- cin >> a >> b;
- vector<int> prime = sieve(1000000);
- if (b <= 1000000)
- {
- for (int p : prime)
- {
- if (p >= a && p <= b)
- {
- cout << p << " ";
- }
- }
- return 0;
- }
- vector<char> used(b - a + 1, 0);
- for (int p : prime)
- {
- ll x = (a + p - 1) / p * p;
- if (used[x - a])
- continue;
- for (; x <= b; x += p)
- {
- used[x - a] = 1;
- }
- }
- for (int i = 0; i < b - a + 1; i++)
- {
- if (!used[i])
- {
- cout << a + i << " ";
- }
- }
- #ifdef LOCAL
- cerr.precision(3);
- cerr << "\nWorking time: " << chrono::duration<double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement