Sum of prime numbers below 2,000,000 giving wrong result
问题 I have to sum all prime numbers below 2,000,000 but my code is giving the wrong result(1,179,908,154 right is 142,913,828,922), since it's working perfectly with lower values I can't figure out what's wrong. #include <iostream> using namespace std; int main(){ unsigned int j, i=2,ans=2, interval=2000000; while(i<=interval){ i++; j=2; while(i!=j){ if(i % j != 0) j++; else{ i++; j=2;} } if (i>=interval) break; cout << i<< endl; ans+=i; } cout << ans; cin.get(); return 0; } 回答1: You are