Cod sursa(job #2140911)

Utilizator liviu2000Dragomirescu Liviu liviu2000 Data 23 februarie 2018 23:19:31
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

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

int gcd(int a,int b,int *x,int *y)
{
    int rez;
    if ( a == 0 )
    {
        *x = 1 ;
        *y = 1 ;
        return b;
    }
    int x1 , y1 ;
    rez = gcd(b%a,a,&x1,&y1) ;
    *x = y1-(b/a)*x1;
    *y = x1 ;
    return rez;
}

int main()
{
    int i , a , n , b , c , cmmdc;
    int xx , yy ;
    fin >> n ;
    for ( i = 1 ; i <= n ; i++ )
    {
        fin >> a >> b >> c ;
        cmmdc = gcd(a,b,&xx,&yy) ;
        if ( c%cmmdc == 0 )
            fout << xx*(c/cmmdc) << " " << yy*(c/cmmdc) << '\n' ;
        else
            fout << "0 " << "0" << '\n' ;
    }
}