Cod sursa(job #1902887)

Utilizator tudoras8tudoras8 tudoras8 Data 4 martie 2017 20:39:40
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

int t, a, b, c;

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

int main(int argc, const char * argv[]) {
    ifstream cin("euclid3.in");
    ofstream cout("euclid3.out");
    
    cin >> t;
    while (t--) {
        cin >> a >> b >> c;
        
        int d, x, y;
        euclid(a, b, &d, &x, &y);
        if (c % d == 0) {
            cout << x * (c / d) << ' ' << y * (c / d) << '\n';
        } else {
            cout << "0 0\n";
        }
    }
    
    return 0;
}