summaryrefslogtreecommitdiff
path: root/content/math/recover.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
commit72bd993483453ed8ebc462f1a33385cd355d486f (patch)
treec5592ba1ed2fed79e26ba6158d097c9ceb43f061 /content/math/recover.cpp
parent98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (diff)
parent35d485bcf6a9ed0a9542628ce4aa94a3326d0884 (diff)
merge mzuenni changes
Diffstat (limited to 'content/math/recover.cpp')
-rw-r--r--content/math/recover.cpp13
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;
+}