Menu
CoddyTech

Factorial

The factorial of a whole number n, written n!, is the product of every whole number from 1 up to n. For example, 4! = 1 × 2 × 3 × 4 = 24. By definition 0! = 1. Your function gets n and returns n!.

Function

factorial(n: integer) → integer
ninteger
the whole number whose factorial you compute
Returnsinteger
the product of every whole number from 1 to n, which is 1 when n is 0

Constraints

  • 0 ≤ n ≤ 12
  • The answer fits in a signed 32-bit integer: the largest one is 12! = 479001600.

Examples

Input
n = 5
Output
120
Explanation
Multiply 1 × 2 × 3 × 4 × 5. The running product goes 1, 2, 6, 24 and ends at 120.

lock icon+11 hidden tests on Submit

challenge icon

Follow-up

100! has 158 digits. Can you count how many zeros it ends with without computing it?

Reset code
def factorial(n):
    # Write code here
Test cases

Case 1

Case 2

Input

n = 5

Expected

120