Submission

Status:

(PPPP)(PPP)(PPP)

Subtask/Task Score:

{40/40}{30/30}{30/30}

Score: 100

User: qweqwe

Problemset: Twin, Cousin, and Sexy Prime

Language: cpp

Time: 0.332 second

Submitted On: 2025-10-16 20:05:02

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define db long double
#define INF 1e15
using namespace std;

vector<bool> primes;
ll l,r;
void soe(){
    for (int i=2;i*i<=r+7;i++){
        if (!primes[i]) continue;
        for (int j=i*i;j<=r+7;j+=i){
            primes[j]=0;
        }
    }
}

int main(){
    cin >> l >> r;
    primes.resize(r+7,1);
    soe();primes[0]=primes[1]=0;
    int tw=0,fo=0,si=0;
    for (int i=l;i<=r;i++){
        if (primes[i] && (primes[i+2] || primes[i-2])) tw++;
        if (primes[i] && (primes[i+4] || primes[i-4])) fo++;
        if (primes[i] && (primes[i+6] || primes[i-6])) si++;
    }cout << tw << "\n" << fo << "\n" << si;
    return 0;
}