Summation of primes

Slow, but only using compiler built-ins (about 5 seconds)

say sum (^2e6).grep: {.&is-prime};

Output:

142913828922

Much faster using external libraries (well under half a second)

use Math::Primesieve;
my $sieve = Math::Primesieve.new;
say sum $sieve.primes(2e6.Int);

Same output

Last updated