题目:
题解:
线性同余方程
#include <bits/stdc++.h>
using namespace std;
long long exgcd(long long a,long long b,long long &x,long long &y)
{
if (!b)
{
x = 1, y = 0;
return a;
}
long long d = exgcd(b, a % b, x, y);
long long z = x;
x = y;
y = z - a / b * y;
return d;
}
int main()
{
long long a,b,m,x,y;
scanf("%lld %lld",&a,&m);
b=1;
long long d=exgcd(a,m,x,y);
{
x=(x*b/d%m+m)%m;
cout<<x<<endl;
}
return 0;
}