Cod sursa(job #2079100)

Utilizator Hidden.bdBurlacu Doru Hidden.bd Data 30 noiembrie 2017 15:49:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 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;

    fin >> T;
    
    while( T-- ){
        
        fin >> a >> b >> c;
        int s_2 = 1, s_1 = 0, t_2 = 0, t_1 = 1;
        
        if( b != 0 ){
            
            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;
            }
            
            //cout << s_1 << " " << t_1 << "\n";
            
            if(c % b) fout << 0 << " " << 0 << "\n";
            
            else fout << s_1 * (c / b) << " " << t_1 * (c / b) << "\n";

        }else cout << 1 << " " << 0;
        
        
    }
    
    
    
    
    
}