noj:http://39.98.219.132:8080/problem/208

#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL gcd(LL a, LL b){
	return (a % b == 0) ? b : gcd(b, a % b);
}
LL x, y;
int main(){
	cin >> x >> y;
	cout << gcd(x, y);
	return 0;
}

acwing:https://www.acwing.com/problem/content/879/

给定 \(a\)\(b\),求出 \(x\)\(y\),使得 \(a * x + b * y = gcd(a, b)\)

LL exgcd(LL a, LL b, LL &x, LL &y){
	if (!b){
	    x = 1, y = 0;
	    return a;
	}
	LL d = exgcd(b, a % b, y, x);
	y -= ( a / b ) * x;
	return d;
}
posted on 2021-11-15 20:03  Hamine  阅读(68)  评论(0编辑  收藏  举报