Cod sursa(job #1238035)

Utilizator alexandru92alexandru alexandru92 Data 5 octombrie 2014 14:58:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
#include <cstdlib>

inline int gcd(int a, int b, int& x, int& y) {
  if (!b) {
    x = 1;
    y = 0;

    return a;
  }
  else {
    int x0, y0, d;

    d = gcd(b, a % b, x0, y0);
    
    x = y0;
    y = x0 - (a / b) * y0;
    
    return d;
  }
}

int main() {
  int T, a, b, c, x, y, d;
  std::ifstream in {"euclid3.in"};
  std::ofstream out {"euclid3.out"};

  for (in >> T; T; --T) {
    in >> a >> b >> c;
    d = gcd(a, b, x, y);
    if (c % d) {
      out << "0 0\n";
    }
    else {
      c /= d;
      out << (c * x) << ' ' << (c * y) << '\n';
    }
  }

  return EXIT_SUCCESS;
}