U737614 题解

· · 个人记录

#include<bits/stdc++.h>
#define int long long
using namespace std;
int exgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
void work(){
    int a, b, x, y, d;
    cin >> a >> b;
    d = exgcd(a, b, x, y);
    cout << d << "\n" << x << " " << y << "\n";
    cout << (x % (b / d) + b / d) % (b / d);
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    while(T--) work();
    return 0;
}