#include <bits/stdc++.h>
using namespace std;
const int MAXPR = (int)1e8;
void calcPrimes() {
auto sum = 2LL;
int cnt = 1;
const int S = round(sqrt(MAXPR));
vector<char> sieve(S + 1, true);
vector<array<int, 2>> cp;
for (int i = 3; i < S; i += 2) {
if (!sieve[i])
continue;
cp.push_back({i, (i * i - 1) / 2});
for (int j = i * i; j <= S; j += 2 * i)
sieve[j] = false;
}
vector<char> block(S);
int high = (MAXPR - 1) / 2;
for (int low = 0; low <= high; low += S) {
fill(block.begin(), block.end(), true);
for (auto &i : cp) {
int p = i[0], idx = i[1];
for (; idx < S; idx += p)
block[idx] = false;
i[1] = idx - S;
}
if (low == 0)
block[0] = false;
for (int i = 0; i < S && low + i <= high; i++)
if (block[i])
++cnt, sum += (low + i) * 2 + 1;
};
cout << "sum = " << sum << endl;
cout << "cnt = " << cnt << endl;
}
int main() {
calcPrimes();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYUFIgPSAoaW50KTFlODsKdm9pZCBjYWxjUHJpbWVzKCkgewogICAgYXV0byBzdW0gPSAyTEw7CiAgICBpbnQgY250ID0gMTsKICAgIAogICAgY29uc3QgaW50IFMgPSByb3VuZChzcXJ0KE1BWFBSKSk7CiAgICB2ZWN0b3I8Y2hhcj4gc2lldmUoUyArIDEsIHRydWUpOwogICAgdmVjdG9yPGFycmF5PGludCwgMj4+IGNwOwogICAgZm9yIChpbnQgaSA9IDM7IGkgPCBTOyBpICs9IDIpIHsKICAgICAgICBpZiAoIXNpZXZlW2ldKQogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICBjcC5wdXNoX2JhY2soe2ksIChpICogaSAtIDEpIC8gMn0pOwogICAgICAgIGZvciAoaW50IGogPSBpICogaTsgaiA8PSBTOyBqICs9IDIgKiBpKQogICAgICAgICAgICBzaWV2ZVtqXSA9IGZhbHNlOwogICAgfQogICAgdmVjdG9yPGNoYXI+IGJsb2NrKFMpOwogICAgaW50IGhpZ2ggPSAoTUFYUFIgLSAxKSAvIDI7CiAgICBmb3IgKGludCBsb3cgPSAwOyBsb3cgPD0gaGlnaDsgbG93ICs9IFMpIHsKICAgICAgICBmaWxsKGJsb2NrLmJlZ2luKCksIGJsb2NrLmVuZCgpLCB0cnVlKTsKICAgICAgICBmb3IgKGF1dG8gJmkgOiBjcCkgewogICAgICAgICAgICBpbnQgcCA9IGlbMF0sIGlkeCA9IGlbMV07CiAgICAgICAgICAgIGZvciAoOyBpZHggPCBTOyBpZHggKz0gcCkKICAgICAgICAgICAgICAgIGJsb2NrW2lkeF0gPSBmYWxzZTsKICAgICAgICAgICAgaVsxXSA9IGlkeCAtIFM7CiAgICAgICAgfQogICAgICAgIGlmIChsb3cgPT0gMCkKICAgICAgICAgICAgYmxvY2tbMF0gPSBmYWxzZTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IFMgJiYgbG93ICsgaSA8PSBoaWdoOyBpKyspCiAgICAgICAgICAgIGlmIChibG9ja1tpXSkKICAgICAgICAgICAgICAgICsrY250LCBzdW0gKz0gKGxvdyArIGkpICogMiArIDE7CiAgICB9OwogICAgCgljb3V0IDw8ICJzdW0gPSAiIDw8IHN1bSA8PCBlbmRsOwoJY291dCA8PCAiY250ID0gIiA8PCBjbnQgPDwgZW5kbDsKfQoKaW50IG1haW4oKSB7CiAgICBjYWxjUHJpbWVzKCk7CglyZXR1cm4gMDsKfQ==