Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Power Tower Modulo

Power Tower Modulo

Difficulty: 2400 6000 ms 128 MB

number-theory

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

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen