Cod sursa(job #1495922)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 3 octombrie 2015 21:39:46
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <cstdio>

long T;

void euclidExtins(long a, long b, long *d, long *x, long *y) {
  if (b == 0) {
    *d = a;
    *x = 1;
    *y = 0;
  } else {
    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("%ld", &T);

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

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

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

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

  return 0;
}