[vijos1781][NOIP2012]同余方程

Description
求关于\(x\)的同余方程\(ax ≡ 1 (mod\;b)\)的最小正整数解。
HINT
\(2≤a,b≤2\times10^9\).
Solution
ax+by=1,扩展欧几里得求解即可.

typedef long long ll;
ll a,b,x,y;
inline void exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){
		x=1;y=0;return;
	}
	exgcd(b,a%b,y,x);
	y=y-a/b*x;
}
inline void Aireen(){
	scanf("%lld%lld",&a,&b);
	exgcd(a,b,x,y);
	if(x<0) x=x+((-x)/b+1)*b; 
	printf("%lld\n",x%b);
}

2017-10-27 13:34:34

原文地址:https://www.cnblogs.com/AireenYe/p/15602452.html