P1781同余方程
代码:
#include<cstdio>
using namespace std;
long long a,b,x,y;
void extend_gcd(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1,y=0;
return;
}
extend_gcd(b,a%b,x,y);
long long t;
t=x,x=y,y=t-(a/b)*y;
}
int main()
{
scanf("%I64d%I64d",&a,&b);
extend_gcd(a,b,x,y);
for(x%=b;x<0;x+=b);
printf("%I64d\n",x);
return 0;
}