import math, strscans const m = 10 ^ 7 echo m let (_, a, n) = stdin.readAll.scanTuple"$i $i" proc powMod(a, n: int): int = if n == 1: a elif n mod 2 == 1: a * powMod(a, n.pred) mod m else: let x = powMod(a, n div 2) (x ^ 2) mod m echo powMod(a, n) mod m