Cod sursa(job #2202434)

Utilizator dan.cantorCantor Dan Alexandru dan.cantor Data 8 mai 2018 19:15:08
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

void ReadFunction();
void EuclidExtins(int a, int b, int& x, int& y, int& d);

int a[101], b[101], c[101], n;
int x, y, d;

int main()
{

    ReadFunction();
    for (int i = 1; i <= n; ++i)
    {

        EuclidExtins(a[i], b[i], x, y, d);


        if (c[i] % (d) == 0)
        {
            fout << x * (c[i] / d) << ' ' << y * (c[i] / d) << '\n';
        }
        else
            fout << 0 << ' ' << 0 << '\n';

    }

}

void ReadFunction()
{
    fin >> n;
    for (int i = 1; i <= n; ++i)
        fin >> a[i] >> b[i] >> c[i];
}

void EuclidExtins(int a, int b, int& x, int& y, int& d)
{
    if (b == 0)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        int x0, y0;
        EuclidExtins(b, a % b, x0, y0, d);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}