Cod sursa(job #2974467)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 4 februarie 2023 09:43:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 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");

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

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