Cod sursa(job #2618351)

Utilizator iancupoppPopp Iancu Alexandru iancupopp Data 24 mai 2020 18:29:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>

using namespace std;

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

int main() {
  ifstream in("euclid3.in");
  ofstream out("euclid3.out");
  
  int q, a, b, c, x, y, d;
  in >> q;
  for (int i = 0; i < q; i ++) {
    in >> a >> b >> c;
    euclid(a, b, d, x, y);
    if (c % d == 0)
      out << x * (c / d) << " " << y * (c / d) << "\n";
    else
      out << "0 0\n";
  }
  
  in.close();
  out.close();
  return 0;
}