diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
| commit | 5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch) | |
| tree | ed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /math/modPowIterativ.cpp | |
| parent | adabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff) | |
updated tcr
Diffstat (limited to 'math/modPowIterativ.cpp')
| -rw-r--r-- | math/modPowIterativ.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/math/modPowIterativ.cpp b/math/modPowIterativ.cpp index f06b4bd..0dc3fb1 100644 --- a/math/modPowIterativ.cpp +++ b/math/modPowIterativ.cpp @@ -1,11 +1,9 @@ -// Laufzeit: O(log (b)) ll powMod(ll a, ll b, ll n) { - if (b == 0) return 1; - ll res = 1; - while (b > 1) { - if (b & 1) res = (a * res) % n; - a = (a * a) % n; - b /= 2; - } - return (a * res) % n; + ll res = 1; + while (b > 0) { + if (b & 1) res = (a * res) % n; + a = (a * a) % n; + b /= 2; + } + return res; } |
