Cod sursa(job #2429829)

Utilizator andrei42Oandrei42O andrei42O Data 11 iunie 2019 12:46:46
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a, b, c, x, y, t;
int euclid(int a, int b, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    int X, Y, D;
    D = euclid(b, a%b, X , Y);
    x = Y;
    y = X - (a / b) * Y;
    return D;
}
int main()
{
    f >> t;
    for(; t; t--)
    {
        f >> a >> b >> c;
        int d = euclid(a, b, x, y);
        if(c % d)
            g << "0 0\n";
        else
            g << c / d * x << ' ' << c / d * y << '\n';
    }
    return 0;
}