summaryrefslogtreecommitdiff
path: root/math/modExp.cpp
diff options
context:
space:
mode:
authorpjungeblut <paul.jungeblut@gmail.com>2014-11-23 23:01:04 +0100
committerpjungeblut <paul.jungeblut@gmail.com>2014-11-23 23:01:04 +0100
commit3bf9e44bf552ef5ceef2a4eef87907cc1a8db09b (patch)
tree0348c99d32361c5787a41740c0d1f5156a5bd031 /math/modExp.cpp
parent4cc304e57566d149582d974cdaf4a7f724c6b5c1 (diff)
parent213662f659ed8b0a95da110ae6eb5e91e2ecae71 (diff)
gebaut
Diffstat (limited to 'math/modExp.cpp')
-rw-r--r--math/modExp.cpp7
1 files changed, 7 insertions, 0 deletions
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