Find the 10001st prime number (in C++)

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;   } 

Replay

Category: c# Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.204 (s). 12 q(s)