Cod sursa(job #2902048)

Utilizator Frant_IoanaFrant Ioana Frant_Ioana Data 15 mai 2022 10:10:49
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 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 = 1;
    }
    else{
        int x1, y1;
        euclid(b, a % b, d, x1, y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}

int main(){
    int t;
    fin >> t;
    
    for(int i = 1; i <= t; i++){
        int a, b, c, d, x, y;
        fin >> a >> b >> c;

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

        if(c % d)
            fout << 0 << ' ' << 0 << '\n';
        else
            fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
}