Cod sursa(job #3156969)

Utilizator Radu_MocanasuMocanasu Radu Radu_Mocanasu Data 13 octombrie 2023 22:00:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int gcd(int a, int b, int &x, int &y){
    if(!b){
        x = 1;
        y = 0;
        return a;
    }
    int x0,y0;
    int d = gcd(b,a % b,x0,y0);
    x = y0;
    y = x0 - (a / b) * y0;
    return d;
}

int main()
{
    int n,i,a,b,x,y,c,e = 0;
    fin >> n;
    for(i = 1; i <= n; i++){
        fin >> a >> b >> c;
        e = 0;
        if(b > a){
            swap(a,b);
            e = 1;
        }
        int d = gcd(a,b,x,y);
        if(c % d){
            fout << "0 0\n";
            continue;
        }
        if(!e) fout << (c / d) * x << " " << (c / d) * y << "\n";
        else fout << (c / d) * y << " " << (c / d) * x << "\n";
        //fout << (c / d) * x << " " << (c / d) * y << "\n";
    }
    return 0;
}