title: Sieve of Eratosthenes implementation
body: <p>I am trying to implement algorithm for Sieve of Eratosthenes but I don't know why this program crashes for larger programs. Initially I was using <code>vector</code> but now I am implementing this using dynamic memory allocation.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cmath&gt;
  #include&lt;cstdlib&gt;
  using namespace std;
  
  unsigned isqrt(unsigned value) {
    return static_cast&lt;unsigned&gt;(sqrt(static_cast&lt;float&gt;(value)));
  }
  
  int main()
  {
      int t;
      cin &gt;&gt; t;
      long long * N;
      long long * M;
      long long n, m;
      N = new long long[t];
      M = new long long[t];
      for(int i = 0; i &lt; t ; i++){
          cin &gt;&gt; M[i] &gt;&gt; N[i];
      }
  
      for(int i = 0; i &lt; t ; i++){
          n = N[i];
          m = M[i];
  
          bool * A;
          A = new bool[n];
          if(A == 0)
          {
              cout &lt;&lt; "Memory cannot be allocated";
              return 0;
          }
  
          for(int i=0;i &lt; n;i++){
              A[i]=true;
          }
          A[0] = false;
          A[1] = false;
  
          unsigned sqrt = isqrt(n);
          for(int i = 2; i &lt;= sqrt; i++)
          {
              if(A[i] == true){
                  for(int j = i*i; j &lt;= n; j = j + i)
                  {
                      A[j] = false;
                  }
              }
          }
  
          for(int i = m;i &lt; n;i++)
          {
              if(A[i] == true )
                  cout &lt;&lt; i &lt;&lt; "\n";
          }
  
          delete[] A;
      }
  
      delete[] M;
      delete[] N;
      return 0;
  }
  </code></pre>
  
  <p>The program crashes for larger values of <code>n</code> and <code>m</code> (~10^16). Kindly help me out.</p>