Cod sursa(job #2079094)

Utilizator Hidden.bdBurlacu Doru Hidden.bd Data 30 noiembrie 2017 15:45:57
Problema Algoritmul lui Euclid extins Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 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;
        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";
        }
        
    }
    
    
    
    
    
}