Cod sursa(job #2037900)
| Utilizator | Data | 12 octombrie 2017 22:31:20 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
int n,a,b,i,x,y,d,c;
int euclid(int a,int b,int &x,int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x0,y0, c = euclid(b,a % b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
return c;
}
int main()
{
f >> n;
for(i = 1;i <= n;i++)
{
f >> a >> b >> d;
c = euclid(a,b,x,y);
if(d % c == 0)
g << x * (d / c) << " " << y * (d / c) << "\n";
else g << "0 0\n";
}
return 0;
}
