summaryrefslogtreecommitdiff
path: root/content/math/modMulIterativ.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'content/math/modMulIterativ.cpp')
-rw-r--r--content/math/modMulIterativ.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/content/math/modMulIterativ.cpp b/content/math/modMulIterativ.cpp
new file mode 100644
index 0000000..611f09a
--- /dev/null
+++ b/content/math/modMulIterativ.cpp
@@ -0,0 +1,9 @@
+ll mulMod(ll a, ll b, ll n) {
+ ll res = 0;
+ while (b > 0) {
+ if (b & 1) res = (a + res) % n;
+ a = (a * 2) % n;
+ b /= 2;
+ }
+ return res;
+}