Cod sursa(job #1967879)

Utilizator MaligMamaliga cu smantana Malig Data 17 aprilie 2017 11:30:56
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");

typedef long long ll;

ll gcd(ll,ll,ll&,ll&);

int main() {
    ll T;
    in>>T;
    while (T--) {
        ll a,b,c,x,y,d;
        in>>a>>b>>c;
        d = gcd(a,b,x,y);

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

    in.close();out.close();
    return 0;
}

ll gcd(ll a,ll b,ll& x,ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    ll x0,y0,d;
    d = gcd(b,a%b,x0,y0);
    x = y0;
    y = x0 - (a/b)*y0;
    return d;
}