From bb5b027079ee6cfd981e1f5b93754eeefc02ef59 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 20 Apr 2022 16:38:15 +0800 Subject: [PATCH] =?UTF-8?q?222.=20=E9=9D=92=E8=9B=99=E7=9A=84=E7=BA=A6?= =?UTF-8?q?=E4=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13561119/ --- AcWing/222/222.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 AcWing/222/222.cpp diff --git a/AcWing/222/222.cpp b/AcWing/222/222.cpp new file mode 100644 index 00000000..eee3b549 --- /dev/null +++ b/AcWing/222/222.cpp @@ -0,0 +1,46 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +long long x, y, n, m, l; + +long long exgcd(long long a, long long b, long long &x, long long &y) { + if (!b) { + x = 1; + y = 0; + return a; + } + + long long g = exgcd(b, a % b, x, y); + long long t = x; + x = y; + y = t - a / b * y; + return g; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> x >> y >> m >> n >> l; + + long long b = n - m, + c = x - y, + xx, yy; + + if (b < 0) { + b = -b; + c = -c; + } + + long long g = exgcd(b, l, xx, yy); + + if (c % g) { + cout << "Impossible" << endl; + } else { + cout << (c / g * xx % (l / g) + (l / g)) % (l / g) << endl; + } + + return 0; +}