Modulo 6

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.

 ``1234567891011121314151617181920`` ``````#include using namespace std; int main() { unsigned long long 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 do{ r = prime % 6; if ((r == 1)||(r==5)) { sum = sum + prime; } prime = prime + 2; }while (prime

 ```OUTPUT: SUM: 166337```
Alternation of code

 ``123456789101112131415161718192021`` ``````#include #include using namespace std; int main() { printf("2 3 "); int m5=25, m7=49, i=5, d=2,sum = 5; for( ; i<100; i+=d, d=6-d ) { if( i!=m5 && i!=m7) { printf("%d ", i); sum += i; } if( m5 <= i ) m5+=10; if( m7 <= i ) m7+=14; } cout << endl << "Sum: " << sum << endl; return 0; } ``````