Cod sursa(job #2585381)

Utilizator sulzandreiandrei sulzandrei Data 19 martie 2020 00:17:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <utility>


using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");
#define ull long long int

void gcd_extended(ull a, ull b, ull *x, ull *y, ull *d)
{
    if(b == 0){
        *x=1;
        *y=0;
        *d = a;
        return;
    }

    ull x0,y0;
    gcd_extended(b,a%b,&x0,&y0,d);

    *x=y0;
    *y=x0-(a/b)*y0;

}

int main ( )
{
    int t;
    in>>t;
    ull a,b,c;


    for(int i=0; i<t; i++)
    {
        ull d=1,x=0,y=0;
        in>>a>>b>>c;
        gcd_extended(a,b,&x,&y,&d);

        cout<<d;

        if(c%d !=0)
        {
            out<<"0 0\n";

        }
        else
        {
            x = (x*c/d);
            y = (y*c/d);
            out<<x<<" "<<y<<'\n';
        }
    }

    return 0;
}