Cod sursa(job #2180927)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 21 martie 2018 12:17:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include<fstream>
using namespace std;
ifstream in ("euclid3.in");
ofstream out ("euclid3.out");
int t;
long long cmmdc (long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    else {
        long long xa,d,ya;
        d = cmmdc (b,a%b,xa,ya);
        x = ya;
        y = xa - (a/b) * ya;
        return d;
    }
}
int main (void) {
    in >> t;
    for (int usl = 1; usl <= t; usl ++) {
        long long a,b,c,d,x=0,y=0;
        in >> a >> b >> c;
        d = cmmdc (a,b,x,y);
        if (c % d == 0) {
            x *= c/d;
            y *= c/d;
            out << x <<" "<< y <<"\n";
        }
        else {
            out <<0 <<" "<<0 <<"\n";
        }
    }
    return 0;
}