lojAC, luogu 80pts求调

P1516 青蛙的约会

```c #include<bits/stdc++.h> using namespace std; #define int long long int exgcd(int a, int b, int &x, int &y){ if(b == 0){ x = 1, y = 0; return a; } int d = exgcd(b, a % b, x, y); int t = x; x = y; y = t - a / b * y; return d; } signed main(){ int x, y, n, m, l; cin>>x>>y>>n>>m>>l; int a = m - n, c = x - y, b = l; if(a < 0) a = -a, c = -c; //ax + by = c int xx = 0, yy = 0; int tt = exgcd(abs(a), abs(b), xx, yy); if(c % tt) puts("Impossible"); else{ int k = c / tt; xx *= k; cout<<((xx % l) + l) % l<<endl; } return 0; } ```
by WRuperD @ 2022-07-12 08:47:33


最后一个判断改成: ```cpp else cout<<c/tt*xx%(b/tt)+b/tt)%(b/tt); ```
by Yizhixiaoyun @ 2022-07-12 09:00:51


|