#CCBCHBA0000072. Chữ số tận cùng của n! (Last Digit of Factorial)

Chữ số tận cùng của n! (Last Digit of Factorial)

Last Digit of Factorial

Source: Phước Hưng OJ

Problem Statement

Given a nonnegative integer n, its factorial is n!=12...*n for n>=1, and 0!=1. Print ONLY the units digit of n! (an integer from 0 to 9), not the full factorial. Keep each intermediate product modulo 10 to avoid huge numbers.

Input

One line containing the integer n.

Output

Print one decimal digit equal to the units digit of n!, followed by a newline.

Subtasks

  • Subtask 1 (20%): 0 <= n <= 4.
  • Subtask 2 (30%): 0 <= n <= 100.
  • Subtask 3 (50%): 0 <= n <= 10^6.

Examples

Example 1

Input:

0

Output:

1

Explanation:

By definition, 0!=1, so the last digit is 1.

Example 2

Input:

4

Output:

4

Explanation:

4!=24, so its last digit is 4.

Example 3

Input:

7

Output:

0

Explanation:

7! includes both a factor 2 and a factor 5, so it is divisible by 10.