Cod sursa(job #2790579)

Utilizator Toni1817Ungureanu Ionut Toni1817 Data 29 octombrie 2021 11:28:25
Problema Algoritmul lui Euclid extins Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T, a, b, c, A[100], B[100], C, x0, y0, x, y;

int main()
{
    int n;
    fin >> T;
    for(int i = 0; i < T; i++)
    {
        fin >> a >> b >> c;
        n = 0;
        A[0] = a, B[0] = b;
        while(B[n])
        {
            n++;
            A[n] = B[n-1];
            B[n] = A[n-1] % B[n-1];
        }
        if(c % A[n])
            fout<<"0" << " " << "0";
        else
        {
            x0 = c / A[n];
            y0 = 0;
            while(n)
            {
                n--;
                x = y0;
                y = x0 - A[n] / B[n] * y0;
                x0 = x;
                y0 = y;
            }
            if(x0 == 0)
             fout << "0" << " " << "0" << "\n";
            else
                fout << x0 << " " << y0 << "\n";
        }
    }
    return 0;
}