Submission
Status:
(PPPP)(PPP)(TSS)
Subtask/Task Score:
{40/40}{30/30}{0/30}
Score: 70
User: letdown
Problemset: Twin, Cousin, and Sexy Prime
Language: cpp
Time: 1.095 second
Submitted On: 2025-10-12 11:03:29
#include <iostream>
#include <set>
#include <vector>
using namespace std;
bool isPrime(long long n) {
if (n < 2) return false;
for (int i = 2; i*i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
int main() {
long long l, u, n;
cin >> l >> u;
vector<long long> primes;
for (long long i = l; i <= u; i++) {
if (isPrime(i)) primes.push_back(i);
}
set<long long> tw, cz, sx;
for (int i = 0; i < primes.size(); i++) {
if (isPrime(primes[i]+2) || isPrime(primes[i]-2)) tw.insert(primes[i]);
if (isPrime(primes[i]+4) || isPrime(primes[i]-4)) cz.insert(primes[i]);
if (isPrime(primes[i]+6) || isPrime(primes[i]-6)) sx.insert(primes[i]);
}
cout << tw.size() << "\n" << cz.size() << "\n" << sx.size();
}