Pagini recente » Rating Radulescu Ioan-Alexandru (alexkolume) | Monitorul de evaluare | Cod sursa (job #1255546) | Cod sursa (job #374220) | Cod sursa (job #2853076)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int ext_gcd(int a,int b, int &x,int &y){
if(b==0){
x = 1;
y = 0;
return a;
}
int x0,y0;
int d = ext_gcd(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b) * y0;
return d;
}
int main()
{
int n, a, b, c, x0,y0;
fin>>n;
for(int i = 0;i < n;i++){
fin>>a>>b>>c;
int d = ext_gcd(a,b,x0,y0);
if(c%d)
fout<<0<<" "<<0<<'\n';
else
fout<<x0*c/d<<" "<<y0*c/d<<'\n';
}
return 0;
}