Cod sursa(job #2605668)

Utilizator rapidu36Victor Manz rapidu36 Data 25 aprilie 2020 17:16:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>

using namespace std;

void euclid(int a, int b, int &x, int &y, int &d)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        d = a;
        return;
    }
    int xx, yy, q = a/b;
    euclid(b, a%b, xx, yy, d);
    x = yy;
    y = xx - q * yy;
}

int main()
{
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");
    int t, a, b, c;
    in >> t;
    for (int i = 0; i < t; i++)
    {
        int x, y, d;
        in >> a >> b >> c;
        euclid(a, b, x, y, d);
        if (c % d != 0)
        {
            out << "0 0\n";
        }
        else
        {
            out << (c/d) * x << " " << (c/d) * y << "\n";
        }
    }
    in.close();
    out.close();
    return 0;
}