Cod sursa(job #2974506)

Utilizator serbanducanDucan Andrei Serban serbanducan Data 4 februarie 2023 10:02:16
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <fstream>

using namespace std;

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

void euclid(long long int a, long long int b, long long int&d, long long int&x, long long int &y);

int n;

int main()
{
    fin >> n;
    for(int i = 0; i < n; i++){
        long long int a, b, c, d, x, y;
        fin >> a >> b >> c;
        euclid(a, b, d, x, y);
        if(c % d == 0){
            if(a * x + b * y == c){
                fout << x << ' ' << y << '\n';
            }
            else
                fout << x * c / d << ' ' << y * c / d << '\n';
        }
        else
            fout << 0 << ' ' << 0 << '\n';
    }
    return 0;
}

void euclid(long long int a, long long int b, long long int&d, long long int&x, long long int &y){

    if(b == 0){
        d = a;
        x = 1;
        y = 1;
    }
    else{
        long long int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }

}