Cod sursa(job #1892737)

Utilizator Aquaryus0Alexandru Benchea Aquaryus0 Data 25 februarie 2017 11:20:44
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <cstdio>

using namespace std;

long int cmmdc(long int x, long int y)
{
    if(y==0)
        return x;
    cmmdc(y, x % y);
}

void euclid_extins (long int x, long int y, long int &k, long int &l)
{
    if(y==0)
    {
        k = 1;
        l = 0;
    }
    else
    {
        long int k0,l0;
        euclid_extins(y,x%y,k0,l0);
        k=l0;
        l=k0-l0*(x/y);
    }
}

void read(long int &t, long int &x, long int&y, long int c)
{
    scanf("%d", &t);
    for(long int i=0; i<t; i++)
    {
        scanf("%d %d %d", &x, &y, &c);
        long int k, l;
        long int d = cmmdc(x,y);
        euclid_extins (x, y, k, l);

        if(c%d)
            cout<<"0 0"<<endl;
        else
            cout<<k*(c/d)<<" "<<l*(c/d)<<endl;

    }
}

int main()
{
    freopen("euclid3.in", "r", stdin);
    //freopen("euclid3.out", "w", stdout);
    long int t, x, y, c;
    read(t,x,y, c);
}