From 7d50a57e6fb3a6c986c28adf2c60b9e39a9afe4a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 19 Apr 2022 21:20:38 +0800 Subject: [PATCH] =?UTF-8?q?P1516=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.luogu.com.cn/record/74258790 --- Luogu/P1516/P1516.cpp | 46 ++++++++++++++++++++++++++++++++++++ Luogu/P1516/data/P1516_1.in | 3 +++ Luogu/P1516/data/P1516_1.out | 3 +++ 3 files changed, 52 insertions(+) create mode 100644 Luogu/P1516/P1516.cpp create mode 100644 Luogu/P1516/data/P1516_1.in create mode 100644 Luogu/P1516/data/P1516_1.out diff --git a/Luogu/P1516/P1516.cpp b/Luogu/P1516/P1516.cpp new file mode 100644 index 00000000..eee3b549 --- /dev/null +++ b/Luogu/P1516/P1516.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; +} diff --git a/Luogu/P1516/data/P1516_1.in b/Luogu/P1516/data/P1516_1.in new file mode 100644 index 00000000..6223d980 --- /dev/null +++ b/Luogu/P1516/data/P1516_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdd9a455b20799d401d0cadd35d31b744e22f56c3e8bfc17bb2096940cc30ca5 +size 56 diff --git a/Luogu/P1516/data/P1516_1.out b/Luogu/P1516/data/P1516_1.out new file mode 100644 index 00000000..f6ae125c --- /dev/null +++ b/Luogu/P1516/data/P1516_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2932062842aa5099d8bf693215b6289f8ffd8f40c35ad8c7525a21a975732488 +size 12