Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Created July 20, 2013 05:23
Show Gist options
  • Select an option

  • Save rfaisal/6043966 to your computer and use it in GitHub Desktop.

Select an option

Save rfaisal/6043966 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<math.h>
int is_prime(int p){
if(p<=1) return 0;
int i=2;
int sqrt_p=sqrt(p);
while(i<=sqrt_p)
if(p%i++==0)
return 0;
return 1;
}
/**
* USAGE: ./a.out 10001
**/
int main(int argc, char *argv[]){
if(argc<2) return 1;
int total = atoi(argv[1]);
int i=1;
int count=0;
while(count<total){
if(is_prime(i)) count++;
i++;
}
return i-1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment