title: Sum of primes below two million. Sieve of Eratosthenes
body: <p>Having a little trouble solving Problem: 'Calculate the sum of primes below two million'. I'm using the 'Sieve of Eratosthenes' method. My method works fine for finding primes till hundred but when I try to find the sum of primes till 2,000,000 I get an incorrect answer.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  long long unsigned int number[2000008];
  int x=2000000LLU;
  int sum()
  {
      int s=0LLU; //stores sum
      for(int y=2; y&lt;=x; y++) //add all the numers in the array from 2 to 2 million
      {
          s+=number[y];
      }
      return s;
  }
  
  int main()
  {
      int k=2;
      for(int i=2; i&lt;=x; i++) //fills in numbers from 2 to 2 million in the array
      {
          number[i]=i;
      }
      for(int j=2; j&lt;=x; j+=1) //starts eliminating multiples of prime numbers from the grid
      {
          if(number[j]!=0) //moves through the grid till it finds a number that hasnt been crossed out. ie. isnt zero                            
          {
              for(int y=j+j; y&lt;=x; y+=j) //when it finds a number, it removes all subsequent multiples of it
              {
                  number[y]=0;
              }
          }
  
      }  
      cout&lt;&lt;endl&lt;&lt;"done"; //shows that the loop has been completed
      cout&lt;&lt;sum(); //outputs the sum of the grid
      return 0;
  }
  </code></pre>