本题用到扩展欧几里得算法,没学过啊,看大佬的解释才懂了一点
数论的海好深
p1082同余方程与扩展欧几里的算法
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
void exgcd(ll a,ll b){
if(b==0){
x=1;
y=0;
return;
}
exgcd(b,a%b);
ll temp = x;
x = y;
y= temp - a/b*x;
return;
}
int main()
{
ios::sync_with_stdio(false);
ll a,b;
cin>>a>>b;
exgcd(a,b);
cout<<(x+b)%b;
return 0;
}