theOldChun

ZJZSZX

[板子]扩欧

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int exgcd(ll a,ll b,ll &x, ll &y){
	if(!b){
		x=1,y=0;return a;
	}
	ll d=exgcd(b,a%b,x,y);
	ll z=x;x=y;y=z-y*(a/b);
	return d;
}
int main(){
	ll a,b,x,y;
	scanf("%lld %lld",&a,&b);
	exgcd(a,b,x,y);
	ll ans=(x%b+b)%b;
	printf("%lld",ans);
	return 0;
}

posted on 2018-11-08 08:10  theOldChun  阅读(109)  评论(0)    收藏  举报

导航