Cod sursa(job #2850319)

Utilizator XRobertoHordoan Roberto Sergiu XRoberto Data 16 februarie 2022 16:53:54
Problema Parcurgere DFS - componente conexe Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

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

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

void solve() {
    int x, y;
    int d;
    fin >> n;
    for(int i = 1; i <= n; i++) {
        fin >> a >> b >> c;
        eex(a, b, &d, &x, &y);
        if(c % d)
            fout << "0 0 \n";
        else
            fout << x * (c / d) << " " << y * (c / d) << "\n";
    }
}

void fclose() {
    fin.close(), fout.close();
}

int main() {
    solve();
    fclose();
    return 0;
}