Cod sursa(job #3224809)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 16 aprilie 2024 11:48:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>
#define QED fin.close(); fout.close(); return 0;
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#define cin fin
#define cout fout

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

int main()
{
    int t, a, b, c, d, x, y, k;
    cin >> t;
    while(t--)
    {
        cin >> a >> b >> c;
        EuclidExtins(a, b, d, x, y);
        if(c % d != 0)
        {
            cout<<"0 0\n";
        }
        else
        {
            k=c/d;
            x*=k;
            y*=k;
            cout << x << ' ' << y << '\n';
        }
    }
    QED
}