Facile 0 risolte 0% di accettazione

Factorial

Multiply all positive integers up to n.

The 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.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.