Cod sursa(job #3207653)

Utilizator Alex_BerbescuBerbescu Alexandru Alex_Berbescu Data 26 februarie 2024 17:50:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
int euclid(int a, int b, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int x1, y1, d;
        d = euclid(b, a % b, x1, y1);
        x = y1;
        y = x1 - (a / b) * y1;
        return d;
    }
}
int a, b, c, n;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int32_t main(int argc, char * argv[])
{
    fin >> n;
    while(n--)
    {
        fin  >> a >> b >> c;
        int d, x, y;
        d = euclid(a, b, x, y);
        if(c % d == 0)
        {
            fout << (c / d) * x << " " << (c / d) * y << '\n';
        }
        else
        {
            fout << 0 << " " << 0 << '\n';
        }
    }
}