Cod sursa(job #3184564)

Utilizator CezarLupuLupu Cezar Andrei CezarLupu Data 16 decembrie 2023 11:00:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");



long long euclid_extins(long long a, long long b, long long& x, long long& y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;

    }
    else
    {
        long long x1,y1;
        int d=euclid_extins(b,a%b,x1,y1);
        x=y1;
        y=x1-y1*(a/b);
        return d;

    }

}
long long n,a,b,c,d,xA,yA;
int main()
{

    f>>n;
    for(int i=1; i<=n; i++)
    {f>>a>>b>>c;
    d=euclid_extins(a,b, xA, yA);
   if(c%d==0)
   {
       g<<xA*(c/d)<<' '<<yA*(c/d)<<'\n';

   }
   else g<<"0 0"<<'\n';
    }

    return 0;
}