Pagini recente » Rating Rares Bilzerian Gherghina (Bilzerian) | Bună frate! | preONI 2007, Runda 1, Clasele 11-12 | Statisticile problemei Coliziuni | Cod sursa (job #3299833)
#include <stdio.h>
#include <assert.h>
inline int egcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = egcd(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return d;
}
int main() {
freopen("euclid3.in", "rt", stdin);
freopen("euclid3.out", "wt", stdout);
int t;
scanf("%d", &t);
assert(t <= 100);
while (t--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
assert(-1e9 <= a && a <= 1e9);
assert(-1e9 <= b && b <= 1e9);
assert(-2e9 <= c && c <= 2e9 && c != 0);
int x, y, d;
d = egcd(a, b, x, y);
if (c % d != 0)
printf("0 0\n");
else
printf("%d %d\n", x * (c / d), y * (c / d));
}
return 0;
}