Cod sursa(job #2058515)

Utilizator Stefan_RaduStefan Radu Stefan_Radu Data 5 noiembrie 2017 18:53:28
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>

using namespace std;

ifstream cin("euclid3.in");
ofstream cout("euclid3.out");

void euclid(int a, int b, int &d, int &x, int &y) {

  if (not b) {
    d = a;
    x = 1;
    y = 0;
    return;
  }

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

int main(int argc, char const *argv[]) {
  
  int n;
  cin >> n;

  int a, b, c, d, x, y;
  while (n --) {

    cin >> a >> b >> c;
    euclid(a, b, d, x, y);

    if (c % d == 0) {
      cout << x * c / d << ' ' << y * c / d << '\n';
    }
    else {
      cout << 0 << ' ' << 0 << '\n';
    }
  }
}