Cod sursa(job #2133494)
| Utilizator | Data | 17 februarie 2018 00:38:07 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
using namespace std;
ifstream fin;
ofstream fout;
int gcd_ext(int a, int b, int &x, int &y)
{
if (b==0)
{
x=1;
y=0;
return a;
}
int x1, y1;
int gcd=gcd_ext(b, a%b, x1, y1);
x=y1;
y=x1-(a/b)*y1;
return gcd;
}
int main()
{
fin.open("euclid3.in");
fout.open("euclid3.out");
int n;
fin >> n;
while(n)
{
--n;
int a, b, c;
fin >> a >> b >> c;
int x, y, d=gcd_ext(a, b, x, y);
if (c%d==0)
fout << x*c/d << " " << y*c/d << "\n";
else
fout << "0 0\n";
}
return 0;
}
