Created
December 29, 2009 14:25
-
-
Save Riduidel/265336 to your computer and use it in GitHub Desktop.
This file contains 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
def primes(long max) { | |
def primes=[:]; primes[2]=4; | |
def i=3; | |
while(i<max) { | |
def isPrime = true; | |
primes.each { k,v -> | |
if(isPrime && v<=i) { | |
isPrime = (i%k!=0); | |
} | |
} | |
if(isPrime) { | |
primes.put(i, i*i); | |
} | |
i+=2; | |
} | |
return primes.keySet(); | |
} | |
long start = System.currentTimeMillis(); | |
NUMBER = 131900005; | |
def p = primes(Math.sqrt(NUMBER).round()); | |
// println "found primes "+p.join(", "); | |
primeDividors = p.findAll {n -> NUMBER%n==0}; | |
println primeDividors.join(", "); | |
long end = System.currentTimeMillis(); | |
println "duration "+((end-start)/1000.0)+" s"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment