Cod sursa(job #2556419)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 24 februarie 2020 21:23:20
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
using namespace std;

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

typedef long long mare;

void euclid(int a, int b, mare &x, mare &y, int &d)
{
    if (b == 0)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        mare x0, y0;
        euclid(b, a%b, x0, y0, d);
        x = y0;
        y = x0 - a/b*y0;
    }
}

int main()
{
    int t, i, a, b, c;
    int gcd;
    mare x, y;
    fin >> t;
    for (i = 1; i<=t; i++)
    {
        fin >> a >> b >> c;
        euclid(a, b, x, y, gcd);
        if (c%gcd == 0)
            fout << x * c/gcd << ' ' << y * c/gcd << '\n';
        else
            fout << "0 0\n";
    }
    return 0;
}