题目
求AX+BY=C的x,y,若无解,输出-1
题目链接:https://codeforces.com/contest/7/problem/C
代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
//#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
ll gcd=0;
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1;
y=0;
return a;
}
ll g=exgcd(b,a%b,x,y);
ll temp=x;
x=y;
y=temp-(a/b)*y;
//cout<<x<<" "<<y<<endl;
return g;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll a,b,c;
cin>>a>>b>>c;
ll x=0,y=0;
gcd=exgcd(a,b,x,y);
if(c%gcd!=0) cout<<-1<<endl;
else{
cout<<-x*c/gcd<<" "<<-y*c/gcd<<endl;
}
return 0;
}