mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 12:18:50 +00:00
222. 青蛙的约会
https://www.acwing.com/problem/content/submission/code_detail/13561119/
This commit is contained in:
parent
bda3a10622
commit
bb5b027079
46
AcWing/222/222.cpp
Normal file
46
AcWing/222/222.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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user