Cod sursa(job #2848044)

Utilizator CobzaruAntonioCobzaru Paul-Antonio CobzaruAntonio Data 12 februarie 2022 09:26:51
Problema Algoritmul lui Euclid extins Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>

using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
long int t,a,b,c,k,x,y,d;
void cmmdc (long int a,long int b,long int &d)
{
    if (b==0)
        d = a;
    else
        cmmdc(b,a%b,d);
}
void euclid (long int a,long int b,long int &d,long int &x,long int &y)
{
    if (b==0)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        long int x0,y0;
        euclid(b,a%b,d,x0,y0);
        x = y0;
        y = x0 - (a/b)*y0;
    }
}
int main()
{
    fin >> t;
    for (k=1; k<=t; k++)
    {
        fin >> a >> b >> c;
        cmmdc(a,b,d);
        if (c%d!=0)
        {
            fout << 0 << ' ' << 0;
        }
        else
        {
            euclid(a,b,d,x,y);
            fout << x*c/d << ' ' << y*c/d << '\n';
        }
    }
    return 0;
}