Cod sursa(job #2910212)

Utilizator radu.seitanSeitan Radu-Catalin radu.seitan Data 18 iunie 2022 18:43:43
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

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

int main(){
    
    int nr = 0;
    
    f >> nr;
    
    for(int i = 0; i < nr; ++i)
    {
    
        int a, b, t, c;
 
        f >> a >> b >> c;
  
        int x = 0, y = 0;
 
        t = euclid_extins(x,y,a,b);
 
        if(c % t)
            g << "0 0" << endl;
        else g << x*(c/t) << ' ' << y*(c/t) << endl;
        
    }
    
    return 0;
}