Cod sursa(job #2897871)

Utilizator alexvali23alexandru alexvali23 Data 5 mai 2022 08:30:09
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void euclid(int a, int b, int & d, long long & x, long long & y)
{
    if(b == 0)
    {
        d = a;
        x = 1;
        y = 1;
    }
    else
    {
        long long x1, y1;
        euclid(b, a % b, d, x1, y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}
int main()
{
    int T, a, b, c, d;
    long long x, y;
    f >> T;
    while(T--)
    {
        f >> a >> b >> c;
        euclid(a, b, d, x, y);
        if(c % d != 0)
            g << 0 << ' ' << 0 << '\n';
        else
            g << x*(c / d) << ' ' << y*(c / d) << '\n';
    }
    return 0;
}