Cod sursa(job #1967163)

Utilizator MaligMamaliga cu smantana Malig Data 15 aprilie 2017 23:20:45
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>

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";
            continue;
        }

        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;
}