Ax+By+C=0,给你A,B,C求x,y
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long INF = 5 * 1e18; void gcd(long long a, long long b, long long& d,long long& x, long long& y) { if(!b) {d = a; x = 1; y = 0;} else { gcd(b, a % b, d, y, x); y -= x * (a / b); } } int main(int argc, char *argv[]) { long long a, b, c, d, x, y; cin >> a >> b >> c; gcd(a, b, d, x, y); if(c % d != 0) puts("-1"); else cout << -x * (c / d) << " " << -y * (c / d) << endl; return 0; }
时间: 2024-10-21 00:07:39