Submission
Status:
(PPPP)(PPP)(TSS)
Subtask/Task Score:
{40/40}{30/30}{0/30}
Score: 70
User: nate213121
Problemset: Twin, Cousin, and Sexy Prime
Language: cpp
Time: 1.088 second
Submitted On: 2026-09-19 11:57:58
#include <bits/stdc++.h>
using namespace std;
vector<int> primes = {2, 3, 5, 7};
bool isPrime(int n)
{
if(n <= 0)
{
return false;
}
if(n == 1)
{
return false;
}
if(n == 2)
{
return true;
}
bool out = true;
for(auto& p:primes)
{
if(p * p > n)
{
break;
}
if(n % p == 0)
{
out = false;
break;
}
}
if(out == true && n > 7)
{
primes.push_back(n);
}
return out;
}
int main()
{
int l, h;
cin >> l >> h;
vector<bool> primeCheck(70000001, false);
for(auto& p:primes)
{
primeCheck[p] = true;
}
for(int n = 2; n <= h + 6; n++)
{
isPrime(n);
}
vector<int> xPrime;
for(auto& p:primes)
{
if(p >= l - 6 && p <= h + 6)
{
xPrime.push_back(p);
}
}
/*for(auto& p:primes)
{
cout << p << " ";
}
cout << endl;*/
int two = 0, four = 0, six = 0;
for(int diff = 2; diff <= 6; diff += 2)
{
//cout << "Diff = " << diff << ": ";
for(auto& p:xPrime)
{
if(
p >= l && p <= h &&
(binary_search(xPrime.begin(), xPrime.end(), p - diff) || binary_search(xPrime.begin(), xPrime.end(), p + diff))
)
{
//cout << p << ", ";
if(diff == 2)
{
two += 1;
}
else if(diff == 4)
{
four += 1;
}
else
{
six += 1;
}
}
}
//cout << endl;
}
//cout << endl;
cout << two << endl << four << endl << six;
return 0;
}