Cod sursa(job #2788236)

Utilizator Seby_AAvram Sebastian Seby_A Data 25 octombrie 2021 12:46:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int main()
{
    int a[50],b[50],A,B,C,n=0,x0,y0,x,y,t;
    fin>>t;
    while(t--)
    {
        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;
            }
            fout<<x0<<" "<<y0;
        }
        fout<<'\n';
    }
    return 0;
}