Power Tower Modulo
Let T = aa···a be a tower of K copies of a. Print T modulo M.
Input: one line with three integers a, K, M.
Output: T mod M.
Constraints:
- 1 ≤ a ≤ 109
- 0 ≤ K ≤ 30
- 1 ≤ M ≤ 109
Sample Tests
Input 1
2 0 5
Output 1
1
Input 2
2 3 100
Output 2
16
Input 3
3 2 7
Output 3
6
Input 4
2 2 1000
Output 4
4
Discussion (opens after you solve — no spoilers before)
No comments yet.