Cod sursa(job #3323128)

Utilizator The_teoTeo Pana The_teo Data 17 noiembrie 2025 11:18:12
Problema Algoritmul lui Euclid extins Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;

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

void EuclidExtins(long long a, long long b, long long &d, long long &x, long long &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else
    {
        long long x0, y0;
        EuclidExtins(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    int T;
    fin >> T;
    while(T--)
    {
        long long a, b, c, d, x, y;
        fin >> a >> b >> c;
        EuclidExtins(a, b, d, x, y);
        if(c % d != 0)
        {
            fout << 0 << 0 << '\n';
        }
        else
        {
            long long k = c / d;
            x *= k;
            y *= k;
            fout << x << ' ' << y << '\n';
        }
    }
    return 0;
}