Cod sursa(job #2245860)

Utilizator dia.ionescuIonescu Diana dia.ionescu Data 26 septembrie 2018 01:25:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void cmmdc(int a, int b, int &x, int &y, int &d){
    if (b == 0){
        x = 1;
        y = 0;
        d = a;
    } else {
        int x0, y0;
        cmmdc(b, a % b, x0, y0, d);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}
int main()
{
    int a, b, c, T, x, y, d;
    fin >> T;
    while (T){
      fin >> a >> b >> c;
      cmmdc(a, b, x, y, d);
      if (c % d == 0)
        fout << x * (c / d) << " " << y * (c / d) << '\n';
      else
        fout << "0 0 \n";
      T--;
    }
}