照着《数学一本通》未过样例求助
查看原帖
照着《数学一本通》未过样例求助
718346
Eat_Cat楼主2023/3/19 19:51

题目(点左边链接)-->

代码:

input:
1 2 3 4 5
answer:
4
my output:
0
code(need help):

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int exgcd(int a,int b,int &x,int &y)
{
	if(!b)
	{
		x=1,y=0;return a;
	}
	int GCD=exgcd(b,a%b,x,y);
	int t;t=x,x=y,y=t-a/b*y;
	return GCD;
}
int x,y,m,n,l,X,Y,GCD;
int main()
{
	cin>>x>>y>>m>>n>>l;
	GCD=exgcd(n-m,l,X,Y);
	if((x-y)%GCD)puts("Impossible");else
	cout<<((ll)(x-y)/GCD*X%(1/GCD)+(1/GCD))%(1/GCD)<<'\n';
 } 
2023/3/19 19:51
加载中...