diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2024-09-11 00:29:27 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2024-09-11 00:29:27 +0200 |
| commit | 0257f0b3c61f203f64c3817dfe19a08f6191517c (patch) | |
| tree | 820d5c1ed1830bad5ee8f1498d9134ca4359393b /content/math/recover.cpp | |
| parent | facc5da35282ef30e5111cdc04942d118f4ae0c5 (diff) | |
moved stuff
Diffstat (limited to 'content/math/recover.cpp')
| -rw-r--r-- | content/math/recover.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/content/math/recover.cpp b/content/math/recover.cpp new file mode 100644 index 0000000..1a593f0 --- /dev/null +++ b/content/math/recover.cpp @@ -0,0 +1,13 @@ +ll sq(ll x) {return x*x;} + +array<ll, 2> recover(ll c, ll m) { + array<ll, 2> u = {m, 0}, v = {c, 1}; + while (m <= 2 * sq(v[0])) { + ll q = u[0] / v[0]; + u[0] -= q * v[0]; + u[1] -= q * v[1]; + swap(u, v); + } + if (v[1] <= 0 || 2 * sq(v[1]) >= m) return {-1, -1}; + return v; +} |
