Educatifu
Open menu

Factorial

Easymath

Compute n! = 1 × 2 × … × n (with 0! = 1).

Input

A single integer n.

Output

The value of n!. (It gets large — pick a language with big integers, or keep within 64-bit for the given limits.)

Examples

Example 1

Input
5
Output
120

1·2·3·4·5 = 120.

Example 2

Input
0
Output
1

0! = 1.

Example 3

Input
10
Output
3628800

10! = 3628800.

Constraints

  • 0 <= n <= 20

Hints

Reveal hint 1

Multiply the numbers from 1 up to n.

Reveal hint 2

0! is defined as 1 — the empty product.

Reference solution (spoiler — try it yourself first)

Approach

Multiply 1 through n; start the running product at 1 so that n = 0 yields 1.

n = int(input())
f = 1
for i in range(2, n + 1):
    f *= i
print(f)

← All practice problems

Bring us the problem, not a perfect specification

Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.

  1. 01Share contextDescribe the workflow, constraint or risk.
  2. 02Clarify togetherWe identify missing facts and useful options.
  3. 03Choose a startAgree a focused assessment or delivery step.
Start a conversation