summaryrefslogtreecommitdiff
path: root/math/modExp.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-08 23:06:01 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-08 23:06:01 +0200
commitf5316545b46edfc511b628430cd883ca2c56f1ca (patch)
treeb6bd3656a1feb8603be51f1974e715efd49a3e59 /math/modExp.cpp
parente452172df888771469ee27e55e940aa0ca66d86a (diff)
New extended euclid code without global variables.
Diffstat (limited to 'math/modExp.cpp')
-rw-r--r--math/modExp.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/math/modExp.cpp b/math/modExp.cpp
index cd0f982..967068c 100644
--- a/math/modExp.cpp
+++ b/math/modExp.cpp
@@ -1,17 +1,15 @@
// Laufzeit: O(log(b))
-ll mult_mod(ll a, ll b, ll n) {
+ll multMod(ll a, ll b, ll n) {
if(a == 0 || b == 0) return 0;
if(b == 1) return a % n;
-
- if(b % 2 == 1) return (a + mult_mod(a, b-1, n)) % n;
- else return mult_mod((a + a) % n, b / 2, n);
+ if(b % 2 == 1) return (a + multMod(a, b-1, n)) % n;
+ else return multMod((a + a) % n, b / 2, n);
}
// Laufzeit: O(log(b))
-ll pow_mod(ll a, ll b, ll n) {
+ll powMod(ll a, ll b, ll n) {
if(b == 0) return 1;
if(b == 1) return a % n;
-
- if(b % 2 == 1) return mult_mod(pow_mod(a, b-1, n), a, n);
- else return pow_mod(mult_mod(a, a, n), b / 2, n);
+ if(b % 2 == 1) return multMod(powMod(a, b-1, n), a, n);
+ else return powMod(multMod(a, a, n), b / 2, n);
}