Cod sursa(job #1200837)

Utilizator bvanceaBogdan Vancea bvancea Data 23 iunie 2014 17:46:42
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>

using namespace std;


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


int main(void) {
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");
    int t;
    in >> t;
    int a, b, c, d, x, y;
    for (int i = 0; i < t; i++) {
        in >> a >> b >> c;
        euclid(a, b, d, x, y);
        if (c % d != 0) {
            out << "0 0\n";
        } else {
            out << x * (c / d) << " " << y * (c / d) << "\n";
        }
    } 
    return 0;
}