Cod sursa(job #3353032)

Utilizator Maries_MihaiMaries Mihai Maries_Mihai Data 3 mai 2026 19:44:02
Problema Algoritmul lui Euclid extins Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

void euclid(int a, int b, int &d, int &x, int  &y){
    if(b == 0){
        d = a;
        x = 1;
        y = 0;
    }
    else{
        int x0,y0;
        euclid(b, a%b, d, x0, y0);

        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    int n;
    fin >> n;

    while(n--){
        int a, b, c;
        fin >> a >> b >> c;

        int  d, x, y;
        euclid(a, b, d, x, y);

        if(c % d == 0){

        x *= c / d;
        y *= c / d;

        }
        else{
            fout << 0 << " " << 0 << '\n';
        }

        fout << x << " " << y << '\n';
    }

    return 0;
}