Submission

Status:

(PPPP)(PPP)(PPP)

Subtask/Task Score:

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

Score: 100

User: Ecir

Problemset: Twin, Cousin, and Sexy Prime

Language: cpp

Time: 0.393 second

Submitted On: 2025-10-01 22:10:05

#include <bits/stdc++.h>
using namespace std;
bool p[70000000];
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int u,v;cin >> u >> v;
    for(int i=2;i*i<=70000000;i++){
        if(p[i]==0){
            for(int j=i*i;j<=70000000;j+=i) p[j]=1;
        }
    }
    // for(int i=3;i<=70000000;i+=2) if(p[i]==0) cout << i << ' '; 
    int ans=0;
    if(u==2) ans++;
    if(u&1) u=u;
    else u++;
    p[0]=1;
    p[1]=1;
    for(int i=u;i<=v;i+=2){
        if(p[i]!=0) continue;
        if((i-2>=0 && p[i-2]==0) || (p[i+2]==0)) ans++;
    }
    cout << ans << '\n';
    ans=0;
    for(int i=u;i<=v;i+=2){
        if(p[i]!=0) continue;
        if((i-4>=0 && p[i-4]==0) || (p[i+4]==0)) ans++;
    }
    cout << ans << '\n';
    ans=0;
    for(int i=u;i<=v;i+=2){
        if(p[i]!=0) continue;
        if((i-6>=0 && p[i-6]==0) || (p[i+6]==0)) ans++;
    }
    cout << ans << '\n';
    ans=0;
    


    return 0;
}