From 3bc27c14ff08cd51c8f07abfc77fbaad9b1e3a5c Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Mon, 17 Jan 2022 09:08:49 +0800 Subject: [PATCH] =?UTF-8?q?P1226=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=B9=82||=E5=8F=96=E4=BD=99=E8=BF=90?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R66944240 --- Luogu/P1226/P1226.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Luogu/P1226/P1226.cpp diff --git a/Luogu/P1226/P1226.cpp b/Luogu/P1226/P1226.cpp new file mode 100644 index 00000000..411a0d1b --- /dev/null +++ b/Luogu/P1226/P1226.cpp @@ -0,0 +1,23 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +long long binpow(long long a, long long b, long long m) { + long long res = 1; + a %= m; + while (b) { + if (b & 1) res = res * a % m; + a = a * a % m; + b >>= 1; + } + return res; +} + +int main() { + long long a, b, p; + cin >> a >> b >> p; + cout << a << '^' << b << " mod " << p << '=' << binpow(a, b, p) << endl; + return 0; +}