c++ - Why doesn't my code generate the prime numbers correctly -


The prime number of less than 10,000,000 is 664,579 but my code only generates 664,214, the source of numbers

  #include & lt; Iostream & gt; # Include & lt; Bitset & gt; # Include & lt; Vector & gt; using namespace std; Const int n = 10000001; Bitset & lt; N & gt; Number; Of vector & lt; Integer & gt; Prime minister; Inline zero sieve () {num.flip (); Number [0] = number [1] = 0; For (int i = 2; i & lt; n; i ++) if (num [i]) {prime.push_back (i); For (long-term unsigned J = i * i; j & lt; n; j + = i) Number [j] = 0; }} Int main () {Sieve (); Cout & lt; & Lt; PrimeSize () & lt; & Lt; Endl; Return 0; }  

i . The fact is that if you allot the results for long periods, the compiler does not promote the type before multiplication.

If I declare a long for unsigned int then your program 664579

Outputs

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -