Cod sursa(job #2257846)

Utilizator stefanut999Paul Colta stefanut999 Data 10 octombrie 2018 16:17:12
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int t,x,y;
void eucleed (int a,int b,int c);
void citire()
{fin>>t;
 int i,a,b,c;
 for(i = 1; i <= t; i++)
    {fin>>a>>b>>c;
     eucleed(a,b,c);
     if( x == INT_MIN || y == INT_MIN)
        fout<<"0 0"<<'\n';
     else
        fout<<x<<' '<<y<<'\n';
    }
}

void eucleed (int a, int b, int c)
{ x = y = INT_MIN;
  int x0 = 1, y0 = 0, x1 = 0, y1 = 1,r;
  while(b)
  {r = a%b;
   c = a / b;
   a = b;
   b = r;
   x = x0 - c * x1;
   x0 = x1;
   x1 = x;
   y = y0 - c * y1;
   y0 = y1;
   y1 = y;
  }
}

int main()
{
    citire();
    fin.close();
    fout.close();

    return 0;
}