All tasks
Mediummathrecursion

Modular Exponentiation

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

One line contains three integers a, b and m. Print a raised to the power b modulo m. By convention 0 to the power 0 equals 1.

Examples

Example 1
Input
2 10 1000
Output
24
Example 2
Input
3 0 7
Output
1

Constraints

  • 0 ≤ a, b ≤ 10^18
  • 1 ≤ m ≤ 10^9
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.