Skip to content

Instantly share code, notes, and snippets.

@IsuraManchanayake
Last active December 10, 2016 12:27
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/5bc763fd564bb410977f68c64bd6b753 to your computer and use it in GitHub Desktop.
Save IsuraManchanayake/5bc763fd564bb410977f68c64bd6b753 to your computer and use it in GitHub Desktop.
primality test using primality_sqrt_bound(int64_t)
L = 100000000 : R = 100100000
test 1 duration : 0.761 s
test 2 duration : 0.762 s
test 3 duration : 0.764 s
test 4 duration : 0.771 s
test 5 duration : 0.741 s
test 6 duration : 0.741 s
test 7 duration : 0.769 s
test 8 duration : 0.744 s
test 9 duration : 0.737 s
test 10 duration : 0.741 s
average of 10 test(s) : 0.7531 s
#include <cmath>
bool primality_sqrt_bound(int64_t a) {
double lim = sqrt(a);
for(int i = 2; i <= lim; i++)
if(a % i == 0)
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment