Cod sursa(job #3185811)

Utilizator Traian_7109Traian Mihai Danciu Traian_7109 Data 20 decembrie 2023 15:22:24
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

signed main()
{
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    int t;
    fin >> t;
    while (t--)
    {
        long long a, b, c;
        fin >> a >> b >> c;
        long long x, y, d = euclid(a, b, x, y);
        if (c % d)
        {
            fout << "0 0\n";
        }
        else 
        {
            fout << x * c / d << ' ' << y * c / d << '\n';
        }
    }
    return 0;
}