Compute the last digit of the infinite product of consecutive integers ending at modulo 10.
The Eternal Immortality
For a positive integer , consider the product
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 ? No — for this problem, the key observation is that the required answer depends only on .
Given an integer , 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 . The result can be found by looking at the repeated behavior of powers of 2 under modulo 10.
Input Format
- A single integer .
Output Format
- Print one integer: the required last digit.
Constraints
- .
- The answer depends only on the least significant digit of .
Example 1
Input
1
Output
1
Explanation
For , the answer is $1$.
Example 2
Input
2
Output
2
Explanation
For , 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.