#include<bits/stdc++.h> usingnamespace std; #define ll long long ll x, y; ll exgcd(ll a, ll b, ll &x, ll &y){ if(!b){ x = 1, y = 0; return a; } ll d = exgcd(b, a % b, x, y); ll t = x; x = y, y = t - y * (a / b); return d; }
intmain(){ ll a,b; cin >> a >> b; exgcd(a, b, x, y); ll ans = (x + b) % b;//最小整数解 cout << ans << endl; }
1 2 3 4 5 6 7 8
boolliEu(ll a, ll b, ll c, ll &x, ll &y){ ll d = exgcd(a, b, x, y); if (c % d != 0) return0; ll k = c / d; x *= k; y *= k; return1; }