Submission

Status:

(-SSS)(SSS)(SSS)

Subtask/Task Score:

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

Score: 0

User: theem1502

Problemset: Twin, Cousin, and Sexy Prime

Language: c

Time: 0.005 second

Submitted On: 2025-09-28 22:37:38

#include <stdio.h>
#include <stdlib.h>

int main() {
    int start, stop;
    scanf("%d %d", &start, &stop);

    int *marked = malloc((stop+100) * sizeof(int));
    
    for (int i = 0; i < stop + 100; i++) {
        marked[i] = 0;
    }
    marked[0] = 1;
    marked[1] = 1;
    for (int i = 2;i < stop + 100; i++) {
        if (marked[i] == 1) {
            continue;
        }
            else {
                for (int j = i +1; j < stop + 100; j++) {
                    if (j % i == 0) {
                        marked[j] = 1;
                    }
                }
            }
    }

    int stoptwin = 0;
    int stopcousin = 0;
    int stopsexy = 0;
    int *copyarray = malloc((stop + 100) * sizeof(int));
    int *secondcopyarray = malloc((stop + 100) * sizeof(int));
    for (int i = 0; i < stop + 100; i++) {
        copyarray[i] = secondcopyarray[i];
        secondcopyarray[i] = marked[i];
    }

    


    for (int i = start; i <= stop; i++) {
        if (secondcopyarray[i] == 1) {
            continue;
        }
        if (secondcopyarray[i + 4] == 0) {
            if (i + 4 <= stop && i >= start) {
                stopcousin++;
            }
            if (i + 4 >= start)
            stopcousin++;
            
        }
    }
    for (int i = 0; i <= stop; i++) {
        if (copyarray[i] == 1) {
            continue;
        }
        if (copyarray[i + 4] == 0 && copyarray[i] == 0) {
            if (i + 4 <=stop && i >= start) {
                
                stopcousin++;
            }
            copyarray[i+ 4] = 2;
            if (i + 4 >= start && i <= stop)
            stopcousin++;

            
        }
        if (copyarray[i] == 2) {

            if(copyarray[i+4] ==0 && i + 4 <= stop && i + 4 >= start) {

                stopcousin++;
                copyarray[i+4] = 2;
            }
        }
    }
    


    for (int i = 0; i <= stop; i++) {
        if (secondcopyarray[i] == 1) {
            continue;
        }
        if (secondcopyarray[i + 2] == 0 && secondcopyarray[i] == 0) {
            if (i + 2 <=stop && i >= start) {
                
                stoptwin++;
            }
            secondcopyarray[i+ 2] = 2;
            if (i + 2 >= start && i <= stop)
            stoptwin++;

            
        }
        if (secondcopyarray[i] == 2) {

            if(secondcopyarray[i+2] ==0 && i + 2 <= stop && i + 2 >= start) {

                stoptwin++;
                secondcopyarray[i+2] = 2;
            }
        }
    }



    for (int i = 0; i <= stop; i++) {
        if (marked[i] == 1) {
            continue;
        }
        if (marked[i + 6] == 0 && marked[i] == 0) {
            if (i + 6 <=stop && i >= start) {
                
                stopsexy++;
            }
            marked[i+ 6] = 2;
            if (i + 6 >= start && i <= stop)
            stopsexy++;

            
        }
        if (marked[i] == 2) {

            if(marked[i+6] ==0 && i + 6 <= stop && i + 6 >= start) {

                stopsexy++;
                marked[i+6] = 2;
            }
        }
    }
    printf("%d\n%d\n%d", stoptwin, stopcousin, stopsexy);
}