Cod sursa(job #2565185)

Utilizator caesar2001Stoica Alexandru caesar2001 Data 2 martie 2020 12:40:35
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#define ll long long

using namespace std;

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

int main() {

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

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

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

    return 0;
}