mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
parent
0d27ec8eb9
commit
7d50a57e6f
46
Luogu/P1516/P1516.cpp
Normal file
46
Luogu/P1516/P1516.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
BIN
Luogu/P1516/data/P1516_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1516/data/P1516_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1516/data/P1516_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1516/data/P1516_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user