Cod sursa(job #2974459)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 4 februarie 2023 09:39:34
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
/// [A][M][C][B][N] ///
#include <bits/stdc++.h>
const int mod = 20173333;
const int inf = 0x3f3f3f3f;
const char sp = ' ', nl = '\n';
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int gcdExtended(int a, int b, int& x, int& y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int gcd = gcdExtended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return gcd;
}

int main() {
	int t;
	fin >> t;
	while (t--) {
        int a, b, x, y, c;
		cin >> a >> b >> c;
        int g = gcdExtended(a, b, x, y);
        if (c % g) {
            fout << 0 << sp << 0 << nl;
        }
        else {
            fout << x * (c / g) << sp << y * (c / g) << nl;
        }
	}
}