Problema
Mostra traduzioneThe factorial of n, written n!, is 1 × 2 × … × n. By definition 0! = 1.
Implement factorial(n).
Input
n: A non-negative integer.
Output
Return n!.
Vincoli
0 ≤ n ≤ 20, so the result fits a signed 64-bit integer.
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! is defined as 1.