90分求助,给关注,谢谢
查看原帖
90分求助,给关注,谢谢
97737
Wsyflying2022楼主2022/2/18 20:45
#include <bits/stdc++.h>
#define int long long
using namespace std;
int t1,t2,m,n,L;
int t,k;
int a,b;
inline void exgcd(int x,int y) {
	if (y==0) {
		a=1,b=0;
		return ;
	}
	exgcd(y,x%y);
	int tmp=a;
	a=b;
	b=tmp-b*(x/y);
}
signed main(){
	scanf("%lld%lld%lld%lld%lld",&t1,&t2,&m,&n,&L);
	t=(t2-t1+L)%L;
	k=(m-n+L)%L;
	int g=__gcd(k,L);
	if (t%g) {
		printf("Impossible\n");
		return 0;
	}
	k/=g,L/=g,t/=g;
	exgcd(k,L);
	printf("%lld\n",(a%L+L)*t%L);
	return 0;
}

2022/2/18 20:45
加载中...