#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
return b?gcd(b,a%b):a;
}
/*
C++ algorithm __gcd(int,int)
*/
// ax + by = gcd(a,b)
LL ex_gcd(LL a,LL b,LL &x,LL &y)
{
if(b==0)
{
x = 1;
y = 0;
return a;
}
LL r = ex_gcd(b,a%b,x,y);
LL t;
t = x, x = y, y = t - a / b * y;
return r;
}
//非递归
//LL exgcd(LL m,LL n,LL &x,LL &y)
//{
// LL x1,y1,x0,y0;
// x0=1; y0=0;
// x1=0; y1=1;
// x=0; y=1;
// LL r=m%n;
// LL q=(m-r)/n;
// while(r)
// {
// x=x0-q*x1; y=y0-q*y1;
// x0=x1; y0=y1;
// x1=x; y1=y;
// m=n; n=r; r=m%n;
// q=(m-r)/n;
// }
// return n;
//}
/*
对于 ax + by = c (c不一定为gcd(a,b))
x,y 只是其中的一组解,
青蛙的约会【数学算法总结】
最新推荐文章于 2022-04-06 23:42:44 发布