Submission
Status:
(PPPP)(PPP)(PPP)
Subtask/Task Score:
{40/40}{30/30}{30/30}
Score: 100
User: speedbuffalo99
Problemset: Twin, Cousin, and Sexy Prime
Language: cpp
Time: 0.325 second
Submitted On: 2026-10-16 16:19:09
#include <iostream>
#include <vector>
using namespace std;
int main() {
int l, u;
cin >> l >> u;
int limit = u + 6;
vector<bool> prime(limit + 1, true);
prime[0] = prime[1] = false;
// Sieve of Eratosthenes
for (int i = 2; i <= limit / i; i++) {
if (prime[i]) {
for (int j = i * i; j <= limit; j += i) {
prime[j] = false;
}
}
}
int twin = 0;
int cousin = 0;
int sexy = 0;
for (int p = l; p <= u; p++) {
if (!prime[p]) continue;
if (prime[p - 2] || prime[p + 2]) {
twin++;
}
if (prime[p - 4] || prime[p + 4]) {
cousin++;
}
if (prime[p - 6] || prime[p + 6]) {
sexy++;
}
}
cout << twin << '\n';
cout << cousin << '\n';
cout << sexy << '\n';
return 0;
}