Cod sursa(job #2017763)
| Utilizator | Data | 2 septembrie 2017 14:14:15 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
using namespace std;
ifstream fin ("Euclid3.in");
ofstream fout ("Euclid3.out");
int a, b, c, t;
int eGCD (int a, int b, int &x, int &y)
{
if ( b == 0 )
{
x = 1;
y = 0;
return a;
}
else
{
int x0 = 0, y0 = 0;
int d = eGCD (b, a%b, x0, y0);
x = y0;
y = x0 - (a/b) * y0;
return d;
}
}
int main()
{
fin>>t;
while (t--)
{
fin>>a>>b>>c;
int x = 0, y = 0;
int d = eGCD(a, b, x, y);
if ( c % d )
fout<<"0 0"<<'\n';
else
fout<< x * (c/d) <<" "<< y * (c/d) <<" "<<'\n';
}
}
