Primorial numbers
Native Raku
With the module Math::Primesieve, this runs in about 1/3 the time vs the built in prime generator.
use Math::Primesieve;
my $sieve = Math::Primesieve.new;
my @primes = $sieve.primes(10_000_000);
sub primorial($n) { [*] @primes[^$n] }
say "First ten primorials: {(primorial $_ for ^10)}";
say "primorial(10^$_) has {primorial(10**$_).chars} digits" for 1..5;Output:
First ten primorials: 1 2 6 30 210 2310 30030 510510 9699690 223092870
primorial(10^1) has 10 digits
primorial(10^2) has 220 digits
primorial(10^3) has 3393 digits
primorial(10^4) has 45337 digits
primorial(10^5) has 563921 digitsImported library
For a real speed boost, load the Perl 5 ntheory library.
Output:
Last updated
Was this helpful?