Cod sursa(job #2480266)

Utilizator vladbatalanBatalan Vlad vladbatalan Data 25 octombrie 2019 10:46:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

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

void Euclid(int a, int b, int &x, int &y)
{
    int aux;
    if(b == 0)
    {
        x = 1;
        y = 0;
        return;
    }
    else
    {
        Euclid(b, a%b, x, y);
        aux = x;
        x = y;
        y = aux - a/b*y;
    }
}

int main()
{
    int T, a ,b ,c, d;
    fin >> T;
    while(T--)
    {
        fin >> a >> b >> c;
        d = __gcd(a, b);
        if(c % d != 0)
        {
            fout << "0 0\n";
            continue;
        }
        int x = 0, y = 0;
        Euclid(a, b, x, y);
        fout << x*(c/d) << ' ' << y*(c/d) << '\n';

    }
    return 0;
}