Cod sursa(job #2170303)

Utilizator LuizaPatroescuPatroescu Luiza LuizaPatroescu Data 14 martie 2018 23:20:54
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;

ifstream fin;
ofstream fout;

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

    int x1, y1;
    int gcd=gcd_ext(b, a%b, x1, y1);
    x=y1;
    y=x1-(a/b)*y1;

    return gcd;
}

int main()
{
    fin.open("euclid3.in");
    fout.open("euclid3.out");

    int n;
    for(fin >> n; n>=1; --n)
    {
        int a, b, c;

        fin >> a >> b >> c;

        int x, y;
        int d=gcd_ext(a, b, x, y);

        if (c%d==0)
            fout << x*(c/d) << " " << y*(c/d) << "\n";
        else
            fout << "0 0\n";
    }

    return 0;
}