• Coding
  • [Exercise] Prime numbers

//primes
#include <iostream>
#include <math.h>
using namespace std;
bool isprime(int n)
{ int lim=sqrt(n)+1;
  if (n==2) return true;
  if (n<2) return false;
  for (int i=2;i<lim; i++)
    {if (n%i==0) return false;
    }
  return true;
}

int main()
{ int j=1,e=1;//j=1 because 2 will not be count in the loop
  while (true)
    { e+=2;// one of 2 consecutive numbers ==0 mod 2
      if (isprime(e)==1) j++;
      if (j==10001)
      {
	 cout<<e<<endl;
         break;
      }
    }
  return 0;
}   
a year later
def isprime(n):
    if n==2: return True
    if n==1 or n%2==0: return False
    if  [i for i in xrange(2,int(n**(0.5)+1)) if n%i==0]==[]: return True
    return False
n,z=0,0
while not z==10001: 
    n+=1
    if isprime(n) is True: z+=1
print n