0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

P1516 青蛙的约会

https://www.luogu.com.cn/record/74258790
This commit is contained in:
Baoshuo Ren 2022-04-19 21:20:38 +08:00
parent 0d27ec8eb9
commit 7d50a57e6f
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 52 additions and 0 deletions

46
Luogu/P1516/P1516.cpp Normal file
View 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

Binary file not shown.

BIN
Luogu/P1516/data/P1516_1.out (Stored with Git LFS) Normal file

Binary file not shown.