Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Created June 17, 2020 14:46
Show Gist options
  • Save rodrigoSaladoAnaya/8207ec81b167f4a7b0f241056c260f79 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/8207ec81b167f4a7b0f241056c260f79 to your computer and use it in GitHub Desktop.
Calculate the prime numbers between 9 and 10000000
for(double N = 9; N < 10000000; N+=2) {
println "${N} ${isPrime(N) ? '' :'__prime__'}"
}
def isPrime(double N) {
def L = Math.ceil(N / 6) - 1;
def t = false;
for(i = 0; i < L; i++) {
def B = (i * 4) + 6;
def Q = (N / B) % 0.5;
def j = Math.floor(N / B) - 1;
t = Q == 0;
if(t || i >= j) {
break
}
}
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment