Cod sursa(job #245607)

Utilizator igsifvevc avb igsi Data 18 ianuarie 2009 13:32:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include<fstream.h>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

void euclid(int a,int b,int &d,int &x,int &y)
{
     int x0,y0;
     if(b==0)
     {
             d=a;
             x=1;
             y=0;
     }
     else
        {
             euclid(b,a%b,d,x0,y0);
             x=y0;
             y=x0-(a/b)*y0;
        }
}

int main()
{
    int a,b,c,d,x,y,t,i;
    
    fin>>t;
    for(i=1;i<=t;i++)
    {
       fin>>a>>b>>c;
       
       euclid(a,b,d,x,y);
       
       if(c%d)
         fout<<"0 0\n";
       else
         fout<<x*(c/d)<<' '<<y*(c/d)<<'\n';
    }
    
    fout.close();
    return 0;
}