Cod sursa(job #1682646)
| Utilizator | Data | 10 aprilie 2016 12:32:45 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <iostream>
#include <fstream>
using namespace std;
int f(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int d = f(b, a%b, x, y);
b = x - (a/b)*y;
a = y;
x = a;
y = b;
return d;
}
int main()
{
int n, a, b, c, d, x, y;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
fin >> n;
for(int i = 1; i<=n; ++i)
{
fin >> a >> b >> c;
d = f(a,b,x,y);
if(c%d != 0)
fout << "0 0\n";
else
fout << x * (c/d) << ' ' << y * (c/d) << '\n';
}
return 0;
}
