Cod sursa(job #2192094)

Utilizator cella.florescuCella Florescu cella.florescu Data 4 aprilie 2018 17:17:31
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

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

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