Cod sursa(job #3216104)

Utilizator AlexInfoIordachioaiei Alex AlexInfo Data 15 martie 2024 17:23:05
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>

using namespace std;

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

#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second

const int NMAX = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int a, b, c, x, y, d, t;

void read()
{
    in >> t;
}

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

void solve()
{
    while (t--)
    {
        in >> a >> b >> c;
        euclid(a, b, d, x, y);
        //inmultesc cu c/d sa ajung la o ecuatie care da = c
        if (c % d == 0)
            out << x * (c / d) << ' ' << y * (c / d);
        else
            out << 0 << ' ' << 0;
        out << '\n';
    }
}

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);

    read();
    solve();

    return 0;
}