Pagini recente » Cod sursa (job #2668397) | Cod sursa (job #544570) | Cod sursa (job #2719054) | Cod sursa (job #767342) | Cod sursa (job #2675395)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
long long euclid_extins(long long a,long long b,long long &x,long long &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
long long fost_x,fost_y;
long long cmmdc = euclid_extins(b,a%b,fost_x,fost_y);
x = fost_y;
y = fost_x + (-a/b)*fost_y;
return cmmdc;
}
int main()
{
long long a,b,x,y,c,t;
f >> t;
for(int i = 1; i<=t; i++)
{
f >> a >> b>> c;
long long cmmdc;
cmmdc = euclid_extins(a,b,x,y);
/// inmultim ecuatia cu c / d (d este cmmdc) pentru a ajunge la ecuatia alg lui euclid extins (daca c/d nu apartine nr naturale atunci ecuatia din pb nu are solutie)
float raport = (c*1.00/cmmdc*1.00) * 1.00;
if(raport == c/cmmdc)
g << x*raport<< " "<< y*raport;
else
g << 0 << " "<< 0;
g<< '\n';
}
}