what you have is numeric overflow the logic of you code is right but your long value probably is a 32-bit integer whose max value is 2,147,483,647 unsigned as you currently have and if unsigned 4,294,967,295 both values are less than 142,913,828,922 what you need is at least a 38-bit integer but the next common integer type is 64-bit. If will use the term
long long
to represent a 64-bit integer. This is common is C++ 11 complier. If
long long
then uses whatever type you complier uses to represent a 64-bit integer. I will only fix your main function as everything else look right.
int main()
{
vector<pr> p = getPrime(1999999);
long long counter = 0;
for (vector<pr>::iterator itr = p.begin(); itr != p.end(); ++itr)
{
if ( (*itr).is_prime == true )
counter += (*itr).num;
}
cout << counter;
}
</pr></pr>