模板,,,

#include<cstdio>
using namespace std;
void exgcd(long long a,long long b,long long &x,long long &y){
	if (b==0) {x=1; y=0;}
	else {exgcd(b,a%b,x,y); int t=y; y=x-a/b*y; x=t;}
}
int main(){
	long long a,b,x,y;
	scanf("%lld %lld\n",&a,&b);
	exgcd(a,b,x,y);
	printf("%lld\n",(x+b)%b);
	return 0;
}

白书上的更简短的模板:

void gcd(LL a,LL b,LL &d,LL &x,LL &y){
	if (!b){
		d=a;
		x=1;
		y=0;
	}else{
		gcd(b,a%b,d,y,x);
		y-=x*(a/b);
	}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-12-26
  • 2022-12-23
  • 2021-11-03
猜你喜欢
  • 2022-02-07
  • 2021-06-24
  • 2022-02-04
  • 2021-10-29
  • 2022-12-23
  • 2021-04-22
相关资源
相似解决方案