Cod sursa(job #2415675)

Utilizator andreisontea01Andrei Sontea andreisontea01 Data 26 aprilie 2019 13:49:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    int n;
    fin >> n;
    while(n){
        int a, b, c;
        fin >> a >> b >> c;
        int x = 0, y = 0, d = 0;
        extins(a, b, d, x, y);
        if(c % d == 0) fout << x * (c / d) << " " << y * (c / d) << "\n";
        else fout << "0 0\n";
        n--;
    }
    return 0;
}