Cod sursa(job #2977984)

Utilizator Elvis_CostinTuca Elvis-Costin Elvis_Costin Data 12 februarie 2023 18:44:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
string np = "euclid3";
ifstream f(np + ".in");
ofstream g(np + ".out");

// #define f cin
// #define g cout

int rez(int a, int b, int &x, int &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    int x1, y1, d;
    d = rez(b, a % b, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
    return d;
}
int main()
{
    int t;
    f >> t;
    for (int a, b, c; f >> a >> b >> c;)
    {
        int d, x, y;
        d = rez(a, b, x, y);
        if (c % d)
            g << "0 0\n";
        else
            g << x * (c / d) << " " << y * (c / d) << '\n';
    }

    return 0;
}