Cod sursa(job #2209789)

Utilizator cezarzbughinCezar Zbughin cezarzbughin Data 4 iunie 2018 18:50:08
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a,b,c,d,x,y,t,cmmdc(int,int,int&,int&);
int main()
{
    f>>t;
    for(;t;t--)
    {
        f>>a>>b>>c;
        d=cmmdc(a,b,x,y);
        if(c%d)
        {
            g<<"0 0\n";
        }
        else
        {
            g<<c/d*x<<' '<<c/d*y<<'\n';
        }
    }
    return 0;
}
int cmmdc(int a,int b,int &x,int &y)
{
    if(!b){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;
}