Cod sursa(job #2669253)

Utilizator Robert.BrindeaBrindea Robert Robert.Brindea Data 6 noiembrie 2020 16:53:32
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>

using namespace std;

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

void euclid(long long a, long long b, long long& d, long long& x, long long& y)
{
    if(b == 0)
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    long long xp, yp;
    euclid(b, a%b, d, xp, yp);
    x = yp;
    y = -(a/b) * yp + xp;
}

long long n;

int main()
{
    fin >> n;
    long long a, b, c, d, x, y;
    for(long long i = 0; i < n; i++)
    {
        fin >> a >> b >> c;
        euclid(a, b, d, x, y);
        if(c%d != 0)
        {
            fout << "0 0\n";
            continue;
        }

        fout << x*c/d << " " << y*c/d << "\n";
    }
    return 0;
}