I wrote this solution for project Euler #7, to find the 10001th prime number using sieve of eratosthenes. It's really slow though. Any suggestions to improve performance (without using more complex sieves like sieve of atkin)?
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#define max 500000
using namespace std;
int main()
{
int ctr = 0;
int i=2,j,n=10001,p=2;
int arr[max];
memset(arr,0,sizeof(arr));
while(1)
{
p=2;
while(p*p<=i)
{
if(arr[p] == 0)
for(j=p*p;j<=i;j+=p)
arr[j] = 1;
p++;
}
if(arr[i]==0)
ctr++;
if(ctr==n)
break;
i++;
}
cout<<i;
}