Cod sursa(job #1679378)

Utilizator razvandRazvan Dumitru razvand Data 7 aprilie 2016 22:10:40
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

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

void gcd(int a, int b, int &x, int &y, int &d) {
    if(b == 0) {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0,y0;
    gcd(b, a%b, x0, y0, d);
    x = y0;
    y = x0 - (a/b)*y0;
}

int main() {

    int n,a,b,c,d,x,y;
    in >> n;

    for(int i = 0; i < n; i++) {

        in >> a >> b >> c;
        gcd(a, b, x, y, d);

        if(c % d != 0) {
            out << 0 << " " << 0 << '\n';
        } else {
            out << x * (c/d) << " " << y * (c/d) << '\n';
        }

    }

    return 0;
}