Cod sursa(job #2507321)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 9 decembrie 2019 23:35:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int t, a, b, c, d, x, y, x0, y0;

void Solve(int a, int b){
    if (!b){
        d = a;
        x = 1;
        y = 0;
    }
    else{
        Solve(b, a % b);
        x0 = x;
        y0 = y;
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main(){
    fin >> t;
    while (t--){
        fin >> a >> b >> c;
        Solve(a, b);
        if (c % d)
            x = y = 0;
        fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}