Cod sursa(job #1761378)
| Utilizator | Data | 22 septembrie 2016 09:29:32 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <cstdio>
using namespace std;
int extins(int a, int b, int &x, int &y)
{
if(!a)
{
x = 0;
y = 1;
return b;
}
int x1, y1;
int d = extins(b%a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return d;
}
int main()
{
int t, a, b, c;
int d, x, y;
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &a, &b, &c);
d = extins(a, b, x, y);
if(c % d)
printf("0 0\n");
else
printf("%d %d\n", x * (c / d), y * (c / d));
}
return 0;
}
