Cod sursa(job #2775602)

Utilizator namesurname01Name Surname namesurname01 Data 16 septembrie 2021 15:12:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>

using namespace std;

void euclid(int a, int b, int &x, int &y, int &gcd)
{
    if(!b)
    {
        x=1;
        y=0;
        gcd=a;
    }
    else
    {
        euclid(b, a%b, x, y, gcd);
        int aux = x;
        x = y;
        y = aux - y*(a/b);
    }
}
int main()
{
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");
    int t, a, b, c, gcd, xg, yg;
    f >> t;
    while(t--)
    {
        f >> a >> b >> c;
        euclid(a, b, xg, yg, gcd);
        if(c % gcd != 0)
            g << 0 <<' '<< 0 <<'\n';
        else
            g << xg*(c/gcd) << ' ' << yg*(c/gcd) <<'\n';
    }
    f.close();
    g.close();
    return 0;
}