Skip to main content
Back to problems
Codeforces
Easy
Math
Number Theory
Bit Manipulation
The Eternal Immortality

Compute the last digit of the infinite product of consecutive integers ending at nn modulo 10.

Acceptance 0%
Problem Statement

The Eternal Immortality

For a positive integer nn, consider the product

P=n(n+1)(n+2)P = n \cdot (n+1) \cdot (n+2) \cdots \infty

This product is clearly not finite, so the useful interpretation is the one used in programming contests: determine the last digit of the value obtained by multiplying all integers from 1 up to nn? No — for this problem, the key observation is that the required answer depends only on nmod10n \bmod 10.

Given an integer nn, output the last digit of the value associated with the problem's eternal multiplication process, which is equivalent to the last digit of the product pattern generated by nn. The result can be found by looking at the repeated behavior of powers of 2 under modulo 10.

Input Format

  • A single integer nn.

Output Format

  • Print one integer: the required last digit.

Constraints

  • 1n1 \le n.
  • The answer depends only on the least significant digit of nn.
Examples
Sample cases returned by the problem API.

Example 1

Input

1

Output

1

Explanation

For n=1n=1, the answer is $1$.

Example 2

Input

2

Output

2

Explanation

For n=2n=2, the answer is $2$.

Show 1 more example

Example 3

Input

10

Output

5

Explanation

The pattern repeats every 4 for powers of 2 modulo 10, and the last digit here is 5.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.