func main() var a: int :: cui@inputInt() var b: int :: cui@inputInt() var c: int :: cui@inputInt() var d: int :: a % c var n: int :: a / c var ans: int :: 0 if(n <> 0) for i(0, c - 1) do ans :+ math@modPow(i, b, c) do ans :% c end for do ans :* n end if for i(0, d) do ans :+ math@modPow(i, b, c) do ans :% c end for do cui@print("\{ans}\n") end func