Cod sursa(job #3151225)

Utilizator Chris_BlackBlaga Cristian Chris_Black Data 20 septembrie 2023 11:15:20
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;


int euclid_extins(int a, int b, int& x, int& y)
{
    if(!b)
    {
        x = 1, y = 0;
        return a;
    }

    int x0, y0;

    int d = euclid_extins(b, a % b, x0, y0);

    x = y0;
    y = x0 - (a / b) * y0;

    return d;
}

void solve()
{
    int a, b, c, x, y;
    cin >> a >> b >> c;

    int d = euclid_extins(a, b, x, y);

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

int main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);

    int t;
    cin >> t;
    while(t --)
        solve();
    return 0;
}