Cod sursa(job #2337586)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 6 februarie 2019 15:58:18
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std ;
ifstream in ("euclid3.in") ;
ofstream out ("euclid3.out") ;
int euclid( int a , int b , int & x , int & y )
{
    if ( !b )
    {
            x = 1 ;
            y = 0 ;
        return a ;
    }
    {
        int x0 , y0 ;
        int u =  euclid ( b , a % b , x0 , y0 ) ;
        x = y0 ;
        y = x0 - y0 * ( a / b ) ;
        return u ;
    }

}
int main ()
{
    int t ; in >> t ;
    while ( t -- )
    {
    int x , y , gcd , z , a , b ;
    in >> a >> b >> z ;
    gcd = euclid ( a , b , x , y ) ;
    if ( z % gcd )  out << 0 << " " << 0 << "\n" ;
    else            out << 1LL * x * z / gcd << " " << 1LL * y * z / gcd << "\n" ;
    }
}