Cod sursa(job #2649310)

Utilizator bubblegumixUdrea Robert bubblegumix Data 14 septembrie 2020 12:26:08
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include<fstream>
#include<assert.h>
using namespace std;


int n;

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

    }
    else
    {
        long x0,y0,d;
        d=euclid3(b,a%b,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
        return d;
    }

}

ifstream f("euclid3.in");
ofstream g("euclid3.out");
int main()
{
     f>>n;
     long a,b,c;
     for(int i=1;i<=n;i++)
     {
         f>>a>>b>>c;
         assert( -1000000000 <= a && a <= 1000000000 );
		 assert( -1000000000 <= b && b <= 1000000000 );
		 assert( -2000000000 <= c && c <= 2000000000 && c != 0 );
         long d,x,y;
         d=euclid3(a,b,x,y);
         if(c%d)
            g<<"0 0";
          else
            g<<x*(c/d)<<" "<<y*(c/d);
          g<<'\n';

     }
return 0;
f.close();
g.close();
}