Cod sursa(job #2770329)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 20 august 2021 15:32:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb

#include <bits/stdc++.h>

using namespace std;

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

int n;

int euclid(int a, int b, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }

    int x1, y1, aux;
    aux = euclid(b, a % b, x1, y1);

    x = y1;
    y = x1 - (a / b) * y1;
    return aux;
}

int main()
{
    f >> n;

    for(int i = 1; i <= n; i++)
    {
        int a, b, c;
        f >> a >> b >> c;

        int x, y, aux;
        aux = euclid(a, b, x, y);

        if(c % aux)
            g << 0 << " " << 0 << "\n";
        else
            g << x * (c / aux) << " " << y * (c / aux) << "\n";
    }

    return 0;
}