Cod sursa(job #1501891)

Utilizator trutruvasilicaHuhurez Marius trutruvasilica Data 13 octombrie 2015 22:24:53
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    ifstream fin ("euclid3.in");
    ofstream fout ("euclid3.out");
    int n, a, b, c;
    fin >> n;
    for (int i = 0; i < n; i++) {
        fin >> a >> b >> c;
        int d, x, y;
        gcd (a, b, d, x, y);
        if (c % d == 0) {
            x *= c / d;
            y *= c / d;
            fout << x << ' ' << y;
        }
        else
            fout << 0 << ' ' << 0;
        fout << "\n";
    }
}