From ae929e4eb692105e5eec2f9a0bd26b06f96a0ae9 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 3 Oct 2021 11:20:47 +0800 Subject: [PATCH] 89. a^b https://www.acwing.com/problem/content/submission/code_detail/8019425/ --- AcWing/89/89.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 AcWing/89/89.cpp diff --git a/AcWing/89/89.cpp b/AcWing/89/89.cpp new file mode 100644 index 00000000..4ffb6f89 --- /dev/null +++ b/AcWing/89/89.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +long long a, b, p, ans = 1; + +int main() { + cin >> a >> b >> p; + a %= p; + while (b) { + if (b & 1) ans = ans * a % p; + a = a * a % p; + b >>= 1; + } + cout << ans % p << endl; + return 0; +}