From ca740ed7caeca4deb09a2fc7912f599555442e15 Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Sat, 22 Nov 2014 11:46:50 +0100 Subject: bisschen LGS --- math/modExp.cpp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 math/modExp.cpp (limited to 'math/modExp.cpp') diff --git a/math/modExp.cpp b/math/modExp.cpp new file mode 100644 index 0000000..f738268 --- /dev/null +++ b/math/modExp.cpp @@ -0,0 +1,7 @@ +ll modPow(ll b, ll e, ll p) { + if (e == 0) return 1; + if (e == 1) return b; + ll half = modPow(b, e / 2, p), res = (half * half) % p; + if (e & 1) res *= b; res %= p; + return res; +} \ No newline at end of file -- cgit v1.2.3