Pagini recente » Cod sursa (job #2377517) | Cod sursa (job #2453557) | Cod sursa (job #278028) | Cod sursa (job #2407298) | Cod sursa (job #2613073)
///ax + b y = d
///d = cmmdc(a, b)
///x, y = ?
#include <iostream>
#include <fstream>
using namespace std;
void cmmdc_extins(int a, int b,int &d, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 1;
d = a;
}
int x2, y2;
cmmdc_extins(b, a % b, d, x2, y2);
x = y2;
y2 = x2 - (a/b)*y2;
}
int cmmdc_extins(int a, int b,int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x2, y2;
int d = cmmdc_extins(b, a%b, x2, y2);
x = y2;
y = x2 - (a/b)*y2;
a = b;
b = a% b;
return d;
}
int main()
{
int n, a, b, c, x, y;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
cin>>n;
while(cin>>a>>b>>c)
{
int d = cmmdc_extins(a, b,x, y);
if(c % d == 0)
cout<<x*c/d<<" "<<y*c/d<<"\n";
else
cout<<0<<" "<<0<<"\n";
}
return 0;
}