summaryrefslogtreecommitdiff
path: root/math/modExp.cpp
diff options
context:
space:
mode:
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