Submission
Status:
(PPPP)(PPP)(PPP)
Subtask/Task Score:
{40/40}{30/30}{30/30}
Score: 100
User: loop
Problemset: Twin, Cousin, and Sexy Prime
Language: cpp
Time: 0.317 second
Submitted On: 2026-10-10 18:33:04
#include <cstdio>
#include <vector>
using namespace std;
// Count primes p in [L, U] whose partner p-g or p+g (g = 2, 4, 6) is also prime; the partner may lie outside the range.
int main() {
int L, U;
scanf("%d %d", &L, &U);
int top = U + 6;
vector<bool> comp(top + 1, false);
comp[0] = comp[1] = true;
for (long long i = 2; i * i <= top; i++)
if (!comp[i])
for (long long j = i * i; j <= top; j += i) comp[j] = true;
int cnt[3] = {0, 0, 0};
for (int p = L; p <= U; p++) {
if (comp[p]) continue;
for (int k = 0; k < 3; k++) {
int g = 2 * (k + 1);
if ((p - g >= 2 && !comp[p - g]) || !comp[p + g]) cnt[k]++;
}
}
printf("%d\n%d\n%d\n", cnt[0], cnt[1], cnt[2]);
return 0;
}