Cod sursa(job #3290642)

Utilizator MerlinTheWizardMelvin Abibula MerlinTheWizard Data 31 martie 2025 14:21:34
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include<bits/stdc++.h>

using namespace std;

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

int main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    
    int t;
    cin >> t;
    while(t--)
    {
        int a, b, c, x, y, ans;
        cin >> a >> b >> c;
        euclid(a, b, ans, x, y);
        if(c % ans)
        {
            cout << "0 0\n";
        }
        else
        {
            cout << x * (c / ans) << " " << y * (c / ans) << "\n";
        }
    }
}