Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/rekursiya-tez-daraja

Fast exponentiation

Medium 1000 ms 128 MB 45%
Share

You are given integers $a$, $b$ and $m$. Find $a^{b} \bmod m$. Assume $0^{0} = 1$.

The base with the exponent and the remainder modulo m

Input

One line with three integers: $a$, $b$ and $m$.

Output

One integer — $a^{b} \bmod m$ (from $0$ to $m - 1$).

Note

$0 \le a \le 10^{9}$
$0 \le b \le 10^{18}$
$1 \le m \le 10^{9} + 7$

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.