Cod sursa(job #1135210)
Utilizator | Data | 7 martie 2014 14:57:33 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
long long gcd(long long a,long long b,long long &x,long long &y)
{
if(!b)
{
x=1;
y=0;
return a;
}
long long x0,y0,d;
d=gcd(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int main()
{
long long t,a,b,c,d,x,y;
fin>>t;
while(t--)
{
fin>>a>>b>>c;
d=gcd(a,b,x,y);
if(c%d)
fout<<"0 0\n";
else
fout<<x*c/d<<" "<<y*c/d<<"\n";
}
return 0;
}