Mai intai trebuie sa te autentifici.
Cod sursa(job #2197963)
Utilizator | Data | 23 aprilie 2018 10:45:46 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.83 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void Euclid_extins_iterativa(int a, int b, int &d, int &x, int &y)
{
int x1 = 0, y1 = 1;
x = 1, y = 0;
while(b != 0)
{
int q = a / b;
int r = a % b;
a = b;
b = r;
int x0 = x - x1 * q;
int y0 = y - y1 * q;
x = x1;
y = y1;
x1 = x0;
y1 = y0;
}
d = a;
}
int main()
{
int T, a, b, c, d, x, y;
f >> T;
for(int i = 1; i <= T; i++)
{
f >> a >> b >> c;
Euclid_extins_iterativa(a, b, d, x, y);
if(c % d == 0)
{
x *= c / d;
y *= c / d;
g << x << ' ' << y << '\n';
}
else g << "0 0\n";
}
return 0;
}