Cod sursa(job #2367412)

Utilizator caesar2001Stoica Alexandru caesar2001 Data 5 martie 2019 10:39:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & -x)

using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

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

    int x0, y0;
    int d = euclid(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b) * y0;

    return d;
}


int main() {

    int ntests;
    in >> ntests;
    while(ntests --) {
        int a, b, c;
        in >> a >> b >> c;
        int x, y;
        int d = euclid(a, b, x, y);

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

    return 0;
}