Cod sursa(job #3284242)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 11 martie 2025 12:13:20
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
// euclid extins.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <fstream>

using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
typedef long long ll;
int n;
int a, b, c;
ll x, y;

ll euclid(ll a, ll b,ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    else
    {
        ll x1, y1,ss;
        ll r = a % b;
        ss=euclid(b, r,x1,y1);
        x = y1;
        y = x1 - a / b * y1;
        return ss;
    }
}

int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
    {
        ll x, y, ss;
        fin >> a >> b >> c;
        ss = euclid(a, b, x, y);
        if (c % ss != 0)
        {
            fout << 0 << " " << 0 << "\n";
        }
        else
        {
            fout << x * (c / ss) << " " << y * (c / ss) << "\n";
        }
    }
    return 0;
}