70求助
查看原帖
70求助
205320
peng_cheng楼主2021/5/12 13:05

哪位大佬指导一下

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x, y, m, n, d, L;
void gcd(ll a, ll b,ll &d,ll &x,ll &y)
{
	ll t;
	if (b == 0)
	{
		d = a;
		x = 1;
		y = 0;
	}
	else
	{
		gcd(b, a % b, d, x, y);
		t = x;
		x = y;
		y = t - (a / b) * y;
	}
}
int main()
{
	ll a, b, d;
	cin >> x >> y >> m >> n >> L;
	if (n < m)swap(m, n), swap(x, y);
	ll c = x - y;
	gcd(m - n, L, d, a, b);
	if (c % d != 0 || m == n)
	{
		cout << "Impossible";
		return 0;
	}
	ll ty = (a * c / d % (L / d) + (L / d)) % (L / d) * -1;
	cout << ty;
	return 0;
}

Just 7070

2021/5/12 13:05
加载中...