#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct timeit {
decltype(chrono::high_resolution_clock::now()) begin;
const string label;
timeit(string label = "???") : label(label) { begin = chrono::high_resolution_clock::now(); }
~timeit() {
auto end = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(end - begin).count();
cerr << duration << "ms elapsed [" << label << "]" << endl;
}
};
const int MAXN = 2e8;
namespace newkactl {
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int LIM = MAXN;
vi eratosthenes() {
const int S = round(sqrt(LIM)), h = (LIM - 1) / 2;
vi pr({2}), sieve(S + 1);
vector<array<int, 2>> cp;
for (int i = 3; i < S; i += 2) {
if (sieve[i])
continue;
cp.push_back({i, i * i / 2 - 1});
for (int j = i * i; j <= S; j += 2 * i)
sieve[j] = true;
}
for (int l = 1; l <= h; l += S) {
array<bool, S> block{};
trav(i, cp) {
int idx = i[1];
for (; idx < S; idx += i[0])
block[idx] = true;
i[1] = idx - S;
}
rep(i, 0, min(S, h - l)) if (!block[i]) pr.push_back((l + i) * 2 + 1);
};
return pr;
}
} // namespace newkactl
namespace pajene {
typedef long long ll;
const int NMAX = MAXN;
bitset<NMAX / 2> bits;
vector<int> sieve() {
bits.set();
vector<int> primes({2});
for (int i = 3; (i >> 1) < bits.size(); i = 2 * bits._Find_next(i >> 1) + 1) {
primes.push_back(i);
// i is prime >= 3
for (ll j = (ll)i * i >> 1; j < bits.size(); j += i)
bits[j] = 0;
}
return primes;
}
} // namespace pajene
namespace kactl {
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAX_PR = MAXN;
bitset<MAX_PR> isprime;
vi eratosthenesSieve() {
int lim = MAX_PR;
isprime.set();
isprime[0] = isprime[1] = 0;
for (int i = 4; i < lim; i += 2)
isprime[i] = 0;
for (int i = 3; i * i < lim; i += 2)
if (isprime[i])
for (int j = i * i; j < lim; j += i * 2)
isprime[j] = 0;
vi pr;
rep(i, 2, lim) if (isprime[i]) pr.push_back(i);
return pr;
}
} // namespace kactl
template <class F> void bench(string name, F f) {
timeit x(name);
f();
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
clock_t begin;
bench("newkactl", newkactl::eratosthenes);
bench("bitset", pajene::sieve);
bench("kactl", kactl::eratosthenesSieve);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CgpzdHJ1Y3QgdGltZWl0IHsKICAgIGRlY2x0eXBlKGNocm9ubzo6aGlnaF9yZXNvbHV0aW9uX2Nsb2NrOjpub3coKSkgYmVnaW47CiAgICBjb25zdCBzdHJpbmcgbGFiZWw7CiAgICB0aW1laXQoc3RyaW5nIGxhYmVsID0gIj8/PyIpIDogbGFiZWwobGFiZWwpIHsgYmVnaW4gPSBjaHJvbm86OmhpZ2hfcmVzb2x1dGlvbl9jbG9jazo6bm93KCk7IH0KICAgIH50aW1laXQoKSB7CiAgICAgICAgYXV0byBlbmQgPSBjaHJvbm86OmhpZ2hfcmVzb2x1dGlvbl9jbG9jazo6bm93KCk7CiAgICAgICAgYXV0byBkdXJhdGlvbiA9IGNocm9ubzo6ZHVyYXRpb25fY2FzdDxjaHJvbm86Om1pbGxpc2Vjb25kcz4oZW5kIC0gYmVnaW4pLmNvdW50KCk7CiAgICAgICAgY2VyciA8PCBkdXJhdGlvbiA8PCAibXMgZWxhcHNlZCBbIiA8PCBsYWJlbCA8PCAiXSIgPDwgZW5kbDsKICAgIH0KfTsKY29uc3QgaW50IE1BWE4gPSAyZTg7CgoKCm5hbWVzcGFjZSBuZXdrYWN0bCB7CiNkZWZpbm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