Cod sursa(job #1495923)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 3 octombrie 2015 21:40:25
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <cstdio>

long long T;

void euclidExtins(long long a, long long b, long long *d, long long *x, long long *y) {
  if (b == 0) {
    *d = a;
    *x = 1;
    *y = 0;
  } else {
    long long x0, y0;
    euclidExtins(b, a%b, d, &x0, &y0);
    *x = y0;
    *y = x0 - a/b * y0;
  }
}

int main() {
  freopen("euclid3.in", "r", stdin);
  freopen("euclid3.out", "w", stdout);

  scanf("%lld", &T);

  for (long long i = 0; i < T; ++i) {
    long long a, b, c, d, x, y;

    scanf("%lld %lld %lld\n", &a, &b, &c);

    euclidExtins(a, b, &d, &x, &y);

    if (c%d == 0) {
      printf("%lld %lld\n", x*c/d, y*c/d);
    } else {
      printf("0 0\n");
    }
  }

  return 0;
}