Cod sursa(job #2559367)

Utilizator viftode4Iftode Vlad viftode4 Data 27 februarie 2020 11:40:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ( "euclid3.in" );
ofstream fout ( "euclid3.out" );
int t;
int a, b, x, y, c;
void euclid_extins ( int a, int b, int&x, int&y ) {
    if ( b == 0 ) {
        x = 1;
        y = 0;
        return;
    }

    int x0, y0;
    euclid_extins ( b, a % b, x0, y0 );
    x = y0;
    y = x0 - y0 * ( a / b );
}
int main() {
    fin >> t;

    while ( t-- ) {
        fin >> a >> b >> c;
        int d = __gcd ( a, b );

        if ( c % d != 0 ) {
            fout << 0 << ' ' << 0 << '\n';
            continue;
        }

        int x, y;
        euclid_extins ( a, b, x, y );
        fout << x* ( c / d ) << ' ' << y* ( c / d ) << '\n';
    }

    return 0;
}