Cod sursa(job #2771069)

Utilizator Tudor06MusatTudor Tudor06 Data 25 august 2021 11:00:00
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

///const int NMAX = 1e3;
const int INF = 1e9;

void euclid( long long a, long long b, long long& x, long long& y, long long& d ) {
    if ( b == 0 ) {
        d = a;
        x = 1;
        y = 0;
    } else {
        long long x0, y0;
        euclid( b, a % b, x0, y0, d );
        x = y0;
        y = x0 - ( a / b ) * y0;
    }
}
int main() {
    ifstream fin( "euclid3.in" );
    ofstream fout( "euclid3.out" );
    int n, i, a, b, c;
    long long x, y, d;
    fin >> n;
    for ( i = 0; i < n; i ++ ) {
        fin >> a >> b >> c;

        d = x = y = 0;
        euclid( a, b, x, y, d );
        if ( c % d != 0 ) {
            fout << "0 0\n";
        } else {
            fout << x * c / d << ' ' << y * c / d << '\n';
        }
    }
    return 0;
}