Cod sursa(job #3249947)

Utilizator andreisharkVirlan Andrei Cristian andreishark Data 18 octombrie 2024 19:35:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>

void gcd(int& x, int& y, int& d, int a, int b) {
  if (b == 0) {
    x = 1;
    y = 0;
    d = a;
    return;
  }

  gcd(x, y, d, b, a % b);
  int temp = x;
  x = y;
  y = temp - (a / b) * y;
}

int main (int argc, char *argv[]) {
  
  std::ifstream fin("euclid3.in");
  std::ofstream fout("euclid3.out");

  int T;
  fin >> T;

  for (int i = 0; i < T; i++) {
    int a, b, c;
    fin >> a >> b >> c;

    int x, y, d;
    gcd(x, y, d, a, b);
    if (c % d) fout << 0 << " " << 0;
    else fout << x*(c / d) << " " << y * (c / d);
    fout << "\n";
  }

  return 0;
}