Cod sursa(job #2455146)

Utilizator mateescu.alexandraMateescu Alexandra mateescu.alexandra Data 10 septembrie 2019 20:52:37
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>

using namespace std;

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

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 a, b, c, d, x, y, m, n;
    f >> a >> b >> c;
    euclid(a, b, d, x, y);
    if(c%d)
        g << "0 0" << '\n';
    else
    {
        m=x*(c/d);
        n=y*(c/d);
        g << m << " " << n;
    }
    f.close();
    g.close();
    return 0;
}