running into max int wall while calculating a large sum

I am trying to create a program that calculates the sum of all the prime numbers under 2,000,000, and although my program is written correctly, it returns the wrong value. I think this is due to a max int issue, or something similar, although I am not sure. I am very new to CS, so it could be many things. I do know that the program is correct though, so it is most likely an int limit.

Any help would be much appreciated!
Try using long long int.
If sizeof(long long) equals 8 (i.e. it's a 64 bit integer), then it is more than enough to hold the sum.

(I know because I've done this same problem before)
Last edited on
Hm, a lot of people are trying to solve this problem. I might have to take a crack at it also!
Topic archived. No new replies allowed.