Cod sursa(job #1466363)

Utilizator diana-t95FMI Tudoreanu Diana Elena diana-t95 Data 29 iulie 2015 00:08:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
void euclid (int a, int b, int &d, int &x, int &y)
{
    if (b == 0) {
        d = a;
        x = 1;
        y = 0;
    } else {
        int x0, y0;
        euclid(b, a%b, d, x0, y0);
        x = y0;
        y = x0 - (a/b)*y0;
    }
}
int main()
{
    int t, a, b, c, d, x, y;
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");
    f>>t;
    while(t--)
    {
        f>>a>>b>>c;
        euclid(a, b, d, x, y);
        if (c%d) g<<"0 0\n";
            else {
                g<<(c/d)*x<<' '<<(c/d)*y<<'\n';
            }
    }
}