Cod sursa(job #2702392)

Utilizator beingsebiPopa Sebastian beingsebi Data 3 februarie 2021 21:11:37
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void solve();
int cmmdc(int, int, int &, int &);
int main()
{
    int t;
    for (f >> t; t; t--)
        solve();
    return 0;
}
void solve()
{
    int a, b, c, x, y;
    f >> a >> b >> c;
    int d = cmmdc(a, b, x, y);
    if (c % d)
        g << "0 0\n";
    else
        g << 1ll * x * (c / d) << " " << 1ll * y * (c / d) << '\n';
}
int cmmdc(int a, int b, int &x, int &y)
{
    if (!b)
    {
        y = 0;
        x = 1;
        return a;
    }
    int x0, y0;
    int d = cmmdc(b, a % b, x0, y0);
    x = y0;
    y = x0 - 1ll * (a / b) * y0;
    return d;
}