Cod sursa(job #1052698)

Utilizator lucian.okapiNestian Lucian-Dan lucian.okapi Data 11 decembrie 2013 18:12:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#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()
{fstream f("euclid3.in", ios::in);
    fstream g("euclid3.out", ios::out);
    int n, i, a, b, c, d, x, y;
    f >> n;
    for (i = 1; i <= n; i++)
    {
        f >> a >> b >> c;
        euclid(a, b, d, x, y);
        if (c%d == 0)g << x*(c / d) << " " << y*(c/d)<< endl;
        else g << 0 << " " << 0 << endl;
    }
    return 0;
}