Cod sursa(job #2786103)

Utilizator MattiaMattia Iojica Mattia Data 20 octombrie 2021 11:30:10
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

int n, a, b, c;

void euclid(int a, int b, int &d, int &x, int &y)
{
    if(!b)
    {
        d = a;
        return;
    }
    else
    {
        euclid(b, a%b, d, x, y);
        int xx = x;
        x = y;
        y = xx - (a / b) * x;
    }
}

int main()
{
    f >> n;

    for(int i = 0; i < n; i++)
    {
        int d, x = 1, y = 0;
        f >> a >> b >> c;

        euclid(a, b, d, x, y);

        if(c % d)
            cout << 0 << " " << 0 << '\n';
        else
            cout << x * (c / d) << " " << y * (c / d) << '\n';
    }
    return 0;
}