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/legendre.cpp | |
| parent | adabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff) | |
updated tcr
Diffstat (limited to 'math/legendre.cpp')
| -rw-r--r-- | math/legendre.cpp | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/math/legendre.cpp b/math/legendre.cpp index adfd3c6..f08755f 100644 --- a/math/legendre.cpp +++ b/math/legendre.cpp @@ -1,17 +1,4 @@ -int legendre(ll a, ll p) { - a %= p; - if (a == 0) return 0; - if (a == 1 || p == 2) return 1; - if (a == 2) return (((p * p - 1) / 8) & 1) ? -1 : 1; - if (isPrime(a)) { - return legendre(p, a) * ((((p - 1) * (a - 1) / 4) & 1) ? -1 : 1); - } else { - map<ll, int> facts; - factor(a, facts); - int res = 1; - for (auto f : facts) - if (f.second & 1) - res *= legendre(f.first, p); - return res; - } +ll legendre(ll a, ll p) { + ll s = powMod(a, p / 2, p); + return s < 2 ? s : -1ll; } |
