using namespace std; int (int a, int b, int& x, int& y) { if(b == 0) { x = 1; y = 0; return a; } int r = exgcd(b, a % b, x, y); int t = x; x = y; y = t - (a / b) * y; return r; } bool linear_equation(int a, int b, int c, int &x, int &y) { int d = exgcd(a, b, x, y); if(c % d) return false; int k = c / d; x *= k; y *= k; return true; } int main(int argc, char const *argv[]) { int x, y; if(linear_equation(47, 30, 1, x, y)) cout << x << " " << y << endl; return 0; }
|
近期评论