#P7318. 「PMOI-4」人赢

    ID: 5865 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学枚举,暴力扩展欧几里德,扩欧矩阵乘法洛谷月赛

「PMOI-4」人赢

Description

Now lhm has an infinite cyclic sequence aa, which satisfies:

  • For every ai(i>2)a_i(i>2) in the sequence, it is always the units digit of ai2×ai1a_{i-2} \times a_{i-1}.

ducati will give lhm the first two terms of the cyclic sequence a1=n,a2=ma_1=n,a_2=m and a position kk. His task is to compute aka_k.

Because lhm is too weak and cannot solve this problem, but he still wants to become "human win", he has to ask the smart you to help him finish it.

Input Format

The first line contains three integers n,m,kn,m,k.

Output Format

Output one integer in one line, representing the digit at position kk in the sequence.

1 6 10
6
7 2 7
2

Hint

[Sample Explanation 1]

The 1st to 10th terms of the sequence are: 1,6,6,6,6,6,6,6,6,61,6,6,6,6,6,6,6,6,\color{red}{6}. So the answer is 66.

[Sample Explanation 2]

The 1st to 7th terms of the sequence are: 7,2,4,8,2,6,27,2,4,8,2,6,\color{red}{2}. So the answer is 22.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (30 pts): 1k1061 \leq k \leq 10^6.
  • Subtask 2 (70 pts): no special restrictions.

For 100%100\% of the testdata, 0n,m90 \leq n,m \leq 9, 1k10121 \leq k \leq 10^{12}.

Translated by ChatGPT 5