Pagini recente » Cod sursa (job #2718395) | Cod sursa (job #465130) | Cod sursa (job #655322) | Cod sursa (job #808678) | Cod sursa (job #1095307)
// gcd extins - O(logN)
// Sa se gaseasca o solutie (x,y) ,
// pentru ecuatia ax+by=c , a,b,c,x,y intregi , a,b,c date
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("euclid3.in"); ofstream g("euclid3.out");
int T,a,b,c;
int gcd(int a,int b,int &x,int &y)
{
if(!b) { x=1 ,y=0; return a; }
int x0,y0,d=gcd(b, a % b , x0 , y0 );
x=y0;
y=x0-(a/b)*y0;
return d;
}
int main()
{
f>>T;
for(int i=1;i<=T;++i)
{
f>>a>>b>>c;
int x,y,d=gcd(a,b,x,y); // d=(a,b);
if(c % d!=0)
{
g<<"0 0\n"; // nu are solutie
continue;
}
x*=(c/d),y*=(c/d);
g<<x<<' '<<y<<'\n';
}
f.close();g.close();
return 0;
}