Cod sursa(job #3232327)

Utilizator marknt20Litoiu Marc-Adrian marknt20 Data 29 mai 2024 22:00:42
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int euclid_extins(int &x, int &y, int a, int b)
{
    int d;
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        d = euclid_extins(x, y, b, a % b);
        int aux = x;
        x = y;
        y = aux - y * (a / b);
    }
    return d;
}
int main()
{
    int a, b, c, d, T;
    f >> T;
    for (int i = 0; i < T; i++)
    {
        f >> a >> b >> c;
        int inv, ins;
        d = euclid_extins(inv, ins, a, b);
        (c % d != 0) ? g << "0 0" << endl : g << inv * (c / d) << " " << ins * (c / d) << endl;
    }
    return 0;
}