This page is still under construction.

Parts of this page are still being built. What you see may change.

Factorial

Interview

Time limit1sMemory limit128 MB

Summary
Read n and print the ones digit of n factorial.
Level

Easy1 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Let nn be a non-negative integer. The value n!n! (read "nn factorial") is defined as follows. If n≤1n \le 1, then n!=1n! = 1. If n>1n > 1, then n!n! is the product of all integers from 11 to nn, that is, n!=1×2×⋯×nn! = 1 \times 2 \times \cdots \times n. For example, 4!=1×2×3×4=244! = 1 \times 2 \times 3 \times 4 = 24.

Write a program that:

  • reads a non-negative integer nn from standard input,
  • computes the units (ones) digit of n!n! in its decimal representation,
  • prints that result to standard output.

Input

The first and only line of standard input contains a single non-negative integer nn (0≤n≤300000 \le n \le 30000).

Output

On the first and only line, print exactly one digit equal to the units digit of n!n! in its decimal representation.

Examples3

  1. Example 1

    Input
    4
    
    Expected output
    4
    
  2. Example 2

    Input
    0
    
    Expected output
    1
    
  3. Example 3

    Input
    5
    
    Expected output
    0