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;
}