Cod sursa(job #3225446)

Utilizator TeodorLuchianovTeo Luchianov TeodorLuchianov Data 17 aprilie 2024 17:09:25
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>

using namespace std;

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

int cmmdc(int a, int b, int &x, int &y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return a;
  }else {
    int ans = cmmdc(b, a % b, x, y);
    int xPrim = x;
    int yPrim = y;
    x = yPrim;
    y = xPrim - (a / b) * yPrim;
    return ans;
  }
}

int main() {

  int t;
  in >> t;
  for(int q = 1;q <= t;q++) {
    int a, b, c, x, y, d;
    in >> a >> b >> c;
    d = cmmdc(a, b, x, y);
    if(c % d == 0) {
      out << 1LL * x * (c / d) << ' ' << 1LL * y * (c / d) << '\n';
    }else {
      out << "0 0\n";
    }
  }
  return 0;
}