Skip to content

Instantly share code, notes, and snippets.

@IsuraManchanayake
Last active December 10, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsuraManchanayake/e5d845139be4f3bc23a7194c344fa0b0 to your computer and use it in GitHub Desktop.
Save IsuraManchanayake/e5d845139be4f3bc23a7194c344fa0b0 to your computer and use it in GitHub Desktop.
primality test using primality_naive(int64_t)
L = 100000 : R = 200000
test 1 duration : 19.897 s
test 2 duration : 20.491 s
average of 2 test(s) : 20.198 s
bool primality_naive(int64_t a) {
int c = 0;
for(int i = 1; i <= a; i++)
if(a % i == 0) {
c++;
if(c > 2)
return false;
}
if(c == 2)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment