Find the 10001st prime number (in C++)
Why is everybody using #include&lt;bits/stdc++.h&gt;? It is so hard to include &lt;cstring&gt; to get memset working?
Why do you need &lt;climits&gt;?
Don't use using namespace std;. It's a bad practice.
Static array of ints with size 500000 is likely too big to fit into stack. Use int * arr = new int[max] and delete [] arr; instead.
Using whole integers to store boolean value is just a waste of memory.
It takes 42 seconds to find result. My version (without sieve) takes about real: 0.015s, user: 0.013s.

#include &lt;iostream&gt;

bool isPrime(int num) {
  for (int i = 2; i*i &lt;= num; ++i) {
    if ((num % i) == 0) return false;
  }
  return num &gt; 1;
}

int main() {
  int i = 2;
  for (int primes = 0; ; ++i) {
    if (isPrime(i)) {
      if (++primes == 10001) {
        std::cout &lt;&lt; i &lt;&lt; "\n";
        break;
      }
    }
  }
}