Mai intai trebuie sa te autentifici.
Cod sursa(job #327153)
| Utilizator | Data | 27 iunie 2009 13:40:42 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.76 kb |
#include <algorithm>
#include <stdio.h>
using namespace std;
int t;
inline int gcd(int a, int b)
{
if (!b)
return a;
return gcd(b, a % b);
}
inline void euclidExtins(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return;
}
euclidExtins(b, a % b, x, y);
int xp = x;
x = y;
y = xp - (a / b) * y;
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
for (scanf("%d", &t); t; t--)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int cmmdc = gcd(a, b);
if (c % cmmdc)
printf("0\n");
else
{
int x, y;
euclidExtins(a, b, x, y);
printf("%d %d\n", c / cmmdc * x, c / cmmdc * y);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}
