summaryrefslogtreecommitdiff
path: root/math/primes.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2017-06-10 23:48:05 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2017-06-10 23:48:05 +0200
commit58001c8c4cc310a0ff834d33c4b92a1d48568dd9 (patch)
tree58359c5b1681e8286abb4c08c90b68ccb2b6fb8c /math/primes.cpp
parent362b09086a49bed54182fc177908ba23c1757660 (diff)
Removing stupid multMod.
Diffstat (limited to 'math/primes.cpp')
-rw-r--r--math/primes.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/math/primes.cpp b/math/primes.cpp
index 1694f6a..bbc63d9 100644
--- a/math/primes.cpp
+++ b/math/primes.cpp
@@ -7,7 +7,7 @@ bool isPrime(ll n) { // Miller Rabin Primzahltest. O(log n)
ll v = powMod(a, d, n); // Implementierung von oben.
if(v == 1 || v == n - 1) continue;
for(int i = 1; i <= j; i++) {
- v = multMod(v, v, n); // Implementierung von oben.
+ v = (v * v) % n;
if(v == n - 1 || v <= 1) break;
}
if(v != n - 1) return false;
@@ -19,9 +19,8 @@ ll rho(ll n) { // Findet Faktor < n, nicht unbedingt prim.
if (~n & 1) return 2;
ll c = rand() % n, x = rand() % n, y = x, d = 1;
while (d == 1) {
- x = (multMod(x, x, n) + c) % n;
- y = (multMod(y, y, n) + c) % n;
- y = (multMod(y, y, n) + c) % n;
+ x = ((x * x) % n + c) % n;
+ y = ((y * y) % n + c) % n;
d = gcd(abs(x - y), n); // Implementierung von oben.
}
return d == n ? rho(n) : d;