思路:很裸的求相遇问题。
#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> using namespace std; const int N = 2e6 + 7; const int M = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 +7; LL a, b, c, m, n, L, x, y; LL exgcd(LL a, LL b, LL &x, LL &y) { if(!b) { x = 1; y = 0; return a; } else { LL gcd, t; gcd = exgcd(b, a % b, x, y); t = x; x = y; y = t - (a / b) * y; return gcd; } } int main() { scanf("%lld%lld%lld%lld%lld", &a, &b, &m, &n, &L); LL gcd = exgcd(n - m, L, x, y); if((a - b) % gcd != 0) { puts("Impossible"); } else { x *= ((a - b) / gcd); x %= L / gcd; if(x < 0) x += abs(L / gcd); printf("%lld ", x); } return 0; } /* */