Cod sursa(job #1428585)

Utilizator dragos_musanMusan Dragos dragos_musan Data 4 mai 2015 19:46:36
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include<fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

void euclid3(int a, int b, int &x, int &y, int &d)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        d = a;
        return;
    }

    int q = a/b;
    int x1, y1;
    euclid3(b, a%b, x1, y1, d);
    x = y1;
    y = x1 - q * y1;
}

int main()
{
    int nrt, a, b, c;

    f >> nrt;

    for(int i = 1; i<=nrt; i++)
    {
        int x, y, d;
        f >> a >> b >> c;
        euclid3(a, b, x, y, d);
        int q = c / d;
        if(c % d)
            x = 0, y = 0;
        g << x * q << ' ' << y * q << '\n';

    }


    return 0;
}