Cod sursa(job #1311631)
| Utilizator | Data | 8 ianuarie 2015 14:02:55 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int T;
int d0,x0,y0;
void euclid_ext(int a,int b)
{
if(b == 0)
{
d0 = a;
x0 = 1;
y0 = 0;
}
else
{
euclid_ext(b,a%b);
int x = y0;
int y = x0 - (a/b)*y0;
x0 = x;
y0 = y;
}
}
int main()
{
int a,b,c;
f>>T;
while(T--)
{
f>>a>>b>>c;
euclid_ext(a,b);
if(c%d0 == 0)
{
c /= d0;
g<<x0*c<<" "<<y0*c<<"\n";
}
else g<<"0 0\n";
}
f.close();
g.close();
return 0;
}
