summaryrefslogtreecommitdiff
path: root/content/other/recover.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2024-08-30 15:04:20 +0200
committermzuenni <michi.zuendorf@gmail.com>2024-08-30 15:04:20 +0200
commitac2d9ad3f2c88bc12420fc439e8d0b4775a11169 (patch)
tree256c13ae0a321e3a705bde52ee679131b9f864d5 /content/other/recover.cpp
parent00b01a954304e50904de97b25639c535e16f259e (diff)
various small improvements
Diffstat (limited to 'content/other/recover.cpp')
-rw-r--r--content/other/recover.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/content/other/recover.cpp b/content/other/recover.cpp
new file mode 100644
index 0000000..0d3c3ea
--- /dev/null
+++ b/content/other/recover.cpp
@@ -0,0 +1,12 @@
+ll sq(ll x) {return x*x;}
+
+pair<ll, ll> recover(ll c, ll m) {
+ array<ll, 3> u = {1, 0, m}, v = {0, 1, c};
+ while (m <= 2 * sq(v[2])) {
+ ll q = u[2] / v[2];
+ for (int i : {0, 1, 2}) u[i] -= q * v[i];
+ swap(u, v);
+ }
+ if (v[1] < 0 || 2 * sq(v[1]) >= m) return {-1, -1};
+ return {v[2], v[1]};
+}