Hello everybody, I have to find the sum of primes below limit.
My program works fine when I try to find primes less than 10. However, when I run it for the sum of primes less than 100, I get 166337 when I am supposed to get 1060. My program works on modular arithmetic, where any prime greater than 3 can be expressed as 1 or 5 mod 6.
unsignedlonglong prime, sum;
int limit = 100;
int r = 0;
prime = 5; // Prime has to start from 5 because the logic works for primes greater than 3
sum = 5; //I let the sum be 5 because 2+3 = 5
r = prime % 6;
if ((r == 1)||(r==5))
sum = sum + prime;
prime = prime + 2;