user
Primorial numbers are those formed by multiplying successive prime numbers.

The primorial number series is:

:   :   * primorial(0) =         1       (by definition)
        * primorial(1) =         2       (2)
        * primorial(2) =         6       (2×3)
        * primorial(3) =       30       (2×3×5)
        * primorial(4) =     210       (2×3×5×7)
        * primorial(5) =   2310       (2×3×5×7×11)
        * primorial(6) = 30030       (2×3×5×7×11×13)
        * **∙ ∙ ∙**

To express this mathematically,   **primorial*n***   is  
the product of the first   *n*   (successive) primes:

:   p
    r
    i
    m
    o
    r
    i
    a

    l

    n
    =

    ∏

    k
    =
    1

    n
    p
    r
    i
    m

    e

    k
    {\displaystyle {\displaystyle primorial\_{n}=\prod \_{k=1}^{n}prime\_{k}}}

:   :   :   :   :   :   ─── where   

                        p
                        r
                        i
                        m

                        e

                        k
                        {\displaystyle {\displaystyle prime\_{k}}}
                           is the   *k**th* *prime number.*

In some sense, generating primorial numbers is similar to factorials.

As with factorials, primorial numbers get large quickly.

Task

* Show the first ten primorial numbers   (0 ──► 9,   inclusive).
* Show the length of primorial numbers whose index is:   10   100   1,000   10,000   and   100,000.
* Show the length of the one millionth primorial number   (optional).
* Use exact integers, not approximations.

By   *length*   (above), it is meant the number of decimal digits in the numbers.

Related tasks

* Sequence of primorial primes
* Factorial
* Fortunate\_numbers

See also

* the MathWorld webpage:   primorial
* the Wikipedia   webpage:   primorial.
* the   OEIS   webpage:   A002110.
assistant
(formerly Perl 6)

### Native Raku

With the module `Math::Primesieve`, this runs in about 1/3 the time vs the built in prime generator.

**Works with**: Rakudo version 2018.09

```
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 digits
```

### Imported library

For a real speed boost, load the Perl 5 ntheory library.

**Library:** ntheory

```
use Lingua::EN::Numbers;
use ntheory:from<Perl5> <pn_primorial>;

say "First ten primorials: ", ^10 .map( { pn_primorial($_) } ).join: ', ';

 for 1..8 {
    my $now = now;
    printf "primorial(10^%d) has %-11s digits - %s\n", $_,
        comma(pn_primorial(10**$_).Str.chars),
        "Elapsed seconds: {(now - $now).round: .001}";
}

```

```
First ten primorials: 1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870
primorial(10^1) has 10          digits - Elapsed seconds: 0.002
primorial(10^2) has 220         digits - Elapsed seconds: 0.015
primorial(10^3) has 3,393       digits - Elapsed seconds: 0.001
primorial(10^4) has 45,337      digits - Elapsed seconds: 0.005
primorial(10^5) has 563,921     digits - Elapsed seconds: 0.139
primorial(10^6) has 6,722,809   digits - Elapsed seconds: 3.015
primorial(10^7) has 77,919,922  digits - Elapsed seconds: 56.483
primorial(10^8) has 885,105,237 digits - Elapsed seconds: 981.71
```