Cod sursa(job #2149998)

Utilizator AndreiDumitrescuAndrei Dumitrescu AndreiDumitrescu Data 3 martie 2018 10:33:54
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;

int euclid(int a, int b, int &x, int &y)
{
    if (b == 0) {
       x = 1;
       y = 0;
       return a;
    } else {
        int x0, y0, rez;
        rez = euclid(b, a % b, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
        return rez;
    }
}

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

int main()
{
    int t, a, b, c;
    f >> t;
    for(int i = 1 ; i <= t; i++)
    {
        f >> a >> b >> c;
        int x, y, rez;
        rez = euclid(a, b, x, y);
        if(c % rez)
            g << "0 0" << '\n';
        else
            g << x *(c / rez)<< " " << y * (c / rez) << '\n';
    }
}