diff options
Diffstat (limited to 'content/math/modPowIterativ.cpp')
| -rw-r--r-- | content/math/modPowIterativ.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/content/math/modPowIterativ.cpp b/content/math/modPowIterativ.cpp new file mode 100644 index 0000000..0dc3fb1 --- /dev/null +++ b/content/math/modPowIterativ.cpp @@ -0,0 +1,9 @@ +ll powMod(ll a, ll b, ll n) { + ll res = 1; + while (b > 0) { + if (b & 1) res = (a * res) % n; + a = (a * a) % n; + b /= 2; + } + return res; +} |
