Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created December 29, 2009 14:25
Show Gist options
  • Save Riduidel/265336 to your computer and use it in GitHub Desktop.
Save Riduidel/265336 to your computer and use it in GitHub Desktop.
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