Cod sursa(job #2822510)
| Utilizator | Data | 24 decembrie 2021 01:02:19 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int cmmdc(int a, int b, int & x, int & y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x1, y1, d = cmmdc(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
int main()
{
int t;
fin >> t;
for(int i = 1; i <= t; i++)
{
int a, b, c;
fin >> a >> b >> c;
int x, y, d = cmmdc(a, b, x, y);
if(c % d)
fout << 0 << ' ' << 0 << '\n';
else
fout << x*(c/d) << ' ' << y*(c/d) << '\n';
}
return 0;
}
