Cod sursa(job #2079070)

Utilizator Hidden.bdBurlacu Doru Hidden.bd Data 30 noiembrie 2017 15:07:23
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int main()
{
    
    int T, a, aux, b, c, r, s_2 = 1, s_1 = 0, t_2 = 0, t_1 = 1;
    fin >> T;
    
    for( int i = 1 ; i <= T ; ++i ){
        
        fin >> a;
        fin >> b;
        fin >> c;
        
        while( a % b ){
            
            r = a % b;
            
            aux = s_2 - (a / b)* s_1;
            s_2 = s_1;
            s_1 = aux;
            
            aux = t_2 - (a / b)* t_1;
            t_2 = t_1;
            t_1 = aux;
            
            a = b;
            b = r;
        }
        
        if( c % b != 0 ) fout << "0 0\n";
        else fout << (c / b) * s_1 << " " << (c / b) * t_1 << "\n";
        
        
    }
    
    
    
    
}