0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

877. 扩展欧几里得算法

https://www.acwing.com/problem/content/submission/code_detail/13592399/
This commit is contained in:
Baoshuo Ren 2022-04-21 19:45:53 +08:00
parent 1372178916
commit be2154478d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

32
AcWing/877/877.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
int n, a, b, x, y;
int exgcd(int a, int b, int& x, int& y) {
if (!b) {
x = 1, y = 0;
return a;
}
int g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
while (n--) {
cin >> a >> b;
exgcd(a, b, x, y);
cout << x << ' ' << y << endl;
}
return 0;
}