我不明白为什么会访问错误
查看原帖
我不明白为什么会访问错误
291604
王茗仟楼主2022/9/21 07:58
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
/*扩展欧几里得
ax+by=c
求解x*/
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
    if(b==0){d=a;x=1;y=0;}
    exgcd(b,a%b,d,x,y);
    ll z=x;x=y;y=z-a/b*y;
}
int main(){
    ll x,y,m,n,L;
    cin>>x>>y>>m>>n>>L;
    if(n<m){swap(m,n);swap(x,y);}
    ll d=0,t=0,tt=0;
    exgcd(n-m,L,d,t,tt);
    if(m==n||(x-y)%d!=0){
        cout<<"Impossible";
        return 0;
    }
    cout<<(t*(x-y)/d%(L/d)+(L/d))%(L/d)<<endl;
    return 0;
}
2022/9/21 07:58
加载中...