Problema
Mostra originale (inglese)Il fattoriale di n, scritto n!, è 1 × 2 × … × n. Per definizione 0! = 1.
Implementa factorial(n).
Input
n: Un intero non negativo.
Output
Restituisci n!.
Vincoli
0 ≤ n ≤ 20, quindi il risultato rientra in un intero con segno a 64 bit.
Esempi
Esempio 1
Input:
n = 5
Output atteso:
expected = 120
Input:
long long n = 5;
Output atteso:
long long expected = 120;
Input:
long n = 5;
Output atteso:
long expected = 120;
Spiegazione
1 × 2 × 3 × 4 × 5 = 120.
Esempio 2
Input:
n = 0
Output atteso:
expected = 1
Input:
long long n = 0;
Output atteso:
long long expected = 1;
Input:
long n = 0;
Output atteso:
long expected = 1;
Spiegazione
0! è definito come 1.