Cod sursa(job #3226024)

Utilizator Sasha_12454Sasha Costea Sasha_12454 Data 19 aprilie 2024 17:38:07
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

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

int t;

int a,b,c;
int d;

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

int main()
{
    ios_base :: sync_with_stdio(false);
    in.tie(NULL);

    in >> t;

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

    return 0;
}