Created
June 17, 2020 14:46
-
-
Save rodrigoSaladoAnaya/8207ec81b167f4a7b0f241056c260f79 to your computer and use it in GitHub Desktop.
Calculate the prime numbers between 9 and 10000000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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