# Factorials

Contents

## Factorial — $$n!$$

The factorial of a positive integer $$n$$, denoted by $$n!$$, is the product of all positive integers less than or equal to $$n$$:

$$n! = 1 × 2 × 3 × … × (n-2) × (n-1) × n$$

According to the convention for an empty product, $$0! = 1$$.

For example,

$$5! = 1 × 2 × 3 × 4 × 5 = 120$$

for (x = 0, 10, print(x, “! = “, x!));
$$\qquad$$
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800

for (x = 0, 10, print(x, “! = “, factorial(x)));
$$\qquad$$
0! = 1.000000000000000000000000000
1! = 1.000000000000000000000000000
2! = 2.000000000000000000000000000
3! = 6.000000000000000000000000000
4! = 24.00000000000000000000000000
5! = 120.0000000000000000000000000
6! = 720.0000000000000000000000000
7! = 5040.000000000000000000000000
8! = 40320.00000000000000000000000
9! = 362880.0000000000000000000000
10! = 3628800.000000000000000000000

## Double Factorial — $$n!!$$

$$n!! = n × (n-2) × (n-4) × …$$

For example,

$$9!! = 9 × 7 × 5 × 3 × 1 = 945$$

f(n) = prod(i = 0, (n – 1) \ 2, n – 2 * i)
for (x = 0, 10, print(x, “!! = “, f(x)));
$$\qquad$$
0!! = 1
1!! = 1
2!! = 2
3!! = 3
4!! = 8
5!! = 15
6!! = 48
7!! = 105
8!! = 384
9!! = 945
10!! = 3840

## Triple Factorial — $$n!!!$$

$$n!! = n × (n-3) × (n-6) × …$$

For example,

## Related to Factorials

### Primorial Numbers — $$n\#$$

The primorial ($$n\#$$) (sequence A002110 in the OEIS) is similar to the factorial, but with the product taken only over the prime numbers. The product of first n primes.

#### Primorial Numbers (First Definition)

OEIS A002110 Primorial numbers (first definition): product of first n primes. Sometimes written prime(n)#.

For example,

$$11\# = 2 × 3 × 5 × 7 × 11 = 2310$$

f(n) = prod(i = 1, n, prime(i));
for (x = 1, 10, print(prime(x), “# = “, f(x)));
$$\qquad$$
2# = 2
3# = 6
5# = 30
7# = 210
11# = 2310
13# = 30030
17# = 510510
19# = 9699690
23# = 223092870
29# = 6469693230

#### Primorial Numbers (Second Definition)

OEIS A034386 Primorial numbers (second definition): n# = product of primes <= n.

\\ Either of these two f() functions will work.
\\ f(n) = my(v = primes(primepi(n))); prod(i = 1, #v, v[i]);
f(n) = lcm(primes([2, n]))
for (x = 1, 15, print(prime(x), “# = “, f(x)));
$$\qquad$$
2# = 1
3# = 2
5# = 6
7# = 6
11# = 30
13# = 30
17# = 210
19# = 210
23# = 210
29# = 210
31# = 2310
37# = 2310
41# = 30030
43# = 30030
47# = 30030

### Superfactorial — sf($$n$$)

For example,

$$\textrm{sf}(4) = 1! × 2! × 3! × 4! = 288$$