Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
437 B
1
Indexable
Never
#include <stdbool.h>
#include <stdio.h>
 
bool isPrime(int n)
{

    if (n == 1 || n == 0)
        return false;
 
    for (int i = 2; i <= n / 2; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
 
int main()
{
    int N = 500000;
    long total = 0;

    for (int i = 1; i <= N; i++) {

        if (isPrime(i)) {
            total += i;
        }
    }

    printf("total: %ld", total);
    return 0;
}
Leave a Comment