Cod sursa(job #3353034)

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

using namespace std;

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

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

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

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

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

        long long d, x, y;
        euclid(abs(a), abs(b), d, x, y);

        if(c % d == 0){

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

        if (a < 0)
            x = -x;
        if (b < 0)
            y = -y;

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

    }

    return 0;
}