Cod sursa(job #2047302)

Utilizator LiverreichIvanov Mihai-Cosmin Liverreich Data 24 octombrie 2017 18:36:19
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
#define ll long long
using namespace std;

ll solve(ll a, ll b, ll &x , ll&y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll d , x0 , y0;
    d = solve(b , a % b , x0 , y0);
    x = y0;
    y = x0 - (a/b) * y0;
    return d;
}

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

    ll a , b , c , d , x , y , t;

    fin>>t;

    for(int i = 0; i < t; i++)
    {
        fin>>a>>b>>c;
        d = solve(a , b , x , y);
        if(c % d)
        {
            fout<<0<<' '<<0<<'\n';
        }
        else
        {
            fout<<x * c/d<<' '<<y * c/d<<'\n';
        }
    }


    return 0;
}