**链接:****传送门 **

题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry"

思路:裸 exgcd


/*************************************************************************
    > File Name: hdu2669.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年05月21日 星期日 18时34分40秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
ll exgcd(ll a,ll b,ll &x,ll &y){
	if( b == 0 ){
		x = 1 ; y = 0 ; return a;
	}
	ll d = exgcd( b , a%b , x , y );
	ll tmp = x;
	x = y;	 y = tmp - a/b*y;
	return d;
}
int main(){
	ll a , b , x , y;
	while(~scanf("%lld%lld",&a,&b)){
		ll d = exgcd( a , b , x , y);
		ll c = 1;
		if( c % d != 0 )	printf("sorry\n");
		else{
			x = x * (c/d);
			x = ( x%(b/d) + b/d )%(b/d);
			printf("%lld %lld\n",x,(1-a*x)/b);
		}
	}
	return 0;
}

相关文章:

  • 2021-12-27
  • 2021-11-13
  • 2021-08-15
  • 2021-06-19
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2019-08-12
  • 2021-06-24
  • 2021-06-20
  • 2021-12-08
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案