Task

Considering in order of length, n, all sequences of consecutive
primes, p, from 2 onwards, where p < 1000 and n>0, select those
sequences whose sum is prime, and for these display the length of the
sequence, the last item in the sequence, and the sum.




#include <stdbool.h>
#include <stdio.h>
 
bool is_prime(int n) {
    int i = 5;
 
    if (n < 2) {
        return false;
    }
 
    if (n % 2 == 0) {
        return n == 2;
    }
    if (n % 3 == 0) {
        return n == 3;
    }
 
    while (i * i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 2;
 
        if (n % i == 0) {
            return false;
        }
        i += 4;
    }
 
    return true;
}
 
int main() {
    const int start = 1;
    const int stop = 1000;
 
    int sum = 0;
    int count = 0;
    int sc = 0;
    int p;
 
    for (p = start; p < stop; p++) {
        if (is_prime(p)) {
            count++;
            sum += p;
            if (is_prime(sum)) {
                printf("The sum of %3d primes in [2, %3d] is %5d which is also prime\n", count, p, sum);
                sc++;
            }
        }
    }
    printf("There are %d summerized primes in [%d, %d)\n", sc, start, stop);
 
    return 0;
}