title: value requires 1000000000 bytes, which is more than max-value-size
body: <p>I am stuck with this problem on spoj.com</p>
  
  <p><a href="http://www.spoj.com/problems/PRIME1/" rel="nofollow">http://www.spoj.com/problems/PRIME1/</a></p>
  
  <p>After reading a bit about prime generation algorithms, I found that "Sieve of Atkins" is the fastest prime generation algorithm. I have partially implemented the algorithm with the help of this tutorial <a href="http://www.geeksforgeeks.org/sieve-of-atkin/" rel="nofollow">http://www.geeksforgeeks.org/sieve-of-atkin/</a></p>
  
  <p>When I ran the code, it gave me segmentation fault. After debugging I came to know that this code is not optimal, it uses more memory, storage. Could someone tell me how can I optimise the program. Here is my code snippet. And yeah, it is incomplete.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int sieveOfAtkin(long int limit)
  {
      // if limit is either 2 or 3, print them
      if (limit &gt;= 2)
      {
          cout &lt;&lt; 2 &lt;&lt; endl;
      }
  
      if (limit &gt;= 3)
      {
          cout &lt;&lt; 3 &lt;&lt; endl;
      }
  
  
      bool sieve[limit];
      for (long int i=0; i&lt;=limit; i++)
          sieve[i] = false;
  
      for (long int x=1; x&lt;limit; x++)
      {
          for (long int y=1; y&lt;limit; y++)
          {
  
              long int n = (4*x*x) + (y*y);
              if (n&lt;=limit &amp;&amp; (n%12==1 || n%12==5))
                  sieve[n] ^= true;
  
              n = (3*x*x) + (y*y);
              if (n&lt;=limit &amp;&amp; (n%12==7))
                  sieve[n] ^= true;
  
              n = (3*x*x) - (y*y);
              if (x&gt;y &amp;&amp; n&lt;=limit &amp;&amp; (n%12==11))
                  sieve[n] ^= true;
          }
      }
  
      for (long int r=5; r*r&lt;limit; r++)
      {
          if(sieve[r])
          {
              for(long int i=r*r; i&lt;limit; i+=r*r)
                  sieve[r] = false;
          }
      }
  
      for (long int i=5; i&lt;limit; i++)
          if(sieve[i])
              cout &lt;&lt; i &lt;&lt; endl; 
  
      return 0;
  }
  
  int main(void)
  {
      long int x;
      cin &gt;&gt; x;
      sieveOfAtkin(x);
      return 0;
  }
  </code></pre>
  
  <hr>