Cod sursa(job #1770043)

Utilizator ZeratulVeress Szilard Zeratul Data 3 octombrie 2016 18:18:22
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include <iostream>
#include <fstream>

#define FOR(i,k,v) for(i = k;i<=v;i++)

using namespace std;

int n,x,y,x0,y0,a,b,c,d,q;

void lnko(int a,int b)
{
    if(a >= b)
    {
        x0 = x0 + a/b;
        a = a % b;
        if(a == 0)
        {
            d = b;
        }
        else
        {
            lnko(a,b);
        }
    }
    else
    {
        y0 = y0 + b/a;
        b = b % a;
        if(b == 0)
        {
            d = a;
        }
        else
        {
            lnko(a,b);
        }
    }
}

int main()
{
    ifstream be("euclid3.in");
    ofstream ki("euclid3.out");

    be>>n;
    FOR(q,1,n)
    {
        be>>a>>b>>c;
        x0 = 0;
        y0 = 0;
        d = 0;
        lnko(a,b);
        if(c%d != 0)
        {
            ki<<0<<" "<<0<<"\n";
        }
        else
        {
            if(x0*a - y0*b == -d)
            {
                x0 = -x0;
            }
            else
            {
                y0 = -y0;
            }
            ki<<x0*c/d<<" "<<y0*c/d<<"\n";
        }

    }




    return 0;
}