Cod sursa(job #2930035)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 27 octombrie 2022 13:00:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

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

int t;

void euclid(int a,int b,int &d,int &x,int &y)
{
    if (b == 0)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        int x0,y0;
        euclid(b,a % b,d,x0,y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    in >> t;
    while (t--)
    {
        int a,b,c,d,x,y;
        in >> a >> b >> c;
        euclid(a,b,d,x,y);
        if (c % d != 0)
            out << "0 0\n";
        else
            out << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}