Cod sursa(job #2254608)

Utilizator AlexAboAbogatoaie Alexandru AlexAbo Data 5 octombrie 2018 17:05:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
int n,a,b,c,d,x,y,cmmdc(int,int,int&,int&);
int main()
{
    f >> n;
    for(;n;n--)
    {
        f >> a >> b >> c;
        d = cmmdc(a,b,x,y);
        if(c%d)
            g << "0 0\n";
        else
        {
            x = c/d * x;
            y = c/d * y;
            g << x << " " << y << "\n";
        }
    }
    return 0;
}
int cmmdc(int a,int b,int &x, int &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    int X,Y,D;
    D = cmmdc(b,a%b, X,Y);
    x = Y;
    y = X-a/b*Y;
    return D;
}