#P7318. Tail Digit Sequence
Tail Digit Sequence
Tail Digit Sequence
Given an infinite sequence \(a\) defined as follows:
- \(a_1 = n\) and \(a_2 = m\).
- For every \(i > 2\), \(a_i = (a_{i-2} \times a_{i-1}) \bmod 10\).
Your task is to compute \(a_k\) given the values of \(n\), \(m\) and \(k\).
Note that since only the last digit is taken at every multiplication step, the sequence becomes periodic. Use this property to efficiently compute \(a_k\) even when \(k\) is large.
inputFormat
The input consists of three integers \(n\), \(m\) and \(k\) separated by spaces, representing the first two digits of the sequence and the position to compute respectively.
\(1 \le n, m \le 9\) and \(k \ge 1\).
outputFormat
Output a single integer, which is the value of \(a_k\) in the sequence.
sample
3 4 5
6