func pow(a: str, b: str, n: int) -> int {
let res:int = 1
let a′:int = mod_str_int(a, n)
let b′:str = reverse_str(b)
for c:chr in b′ do {
let d:int = digit_chr_to_int(c)
res = res * mod_pow(a′, d, n) % n // tính (29^1)^4 * (29^10)^5 * (29^100)^9 * (29^1000)^8
a′ = mod_pow(a′, 10, n) // tính 29^1, 29^10, 29^100, 29^1000
}
return res
}
func mod_str_int(a: str, n: int) -> int { ... } // "1729" % 100 -> 29
func reverse_str(s: str) -> str { ... }
func digit_chr_to_int(c: chr, n: int) -> int { ... }
func mod_pow(a: int, b: int, n: int) -> int { ... }