Cod sursa(job #3171191)

Utilizator EdyIordacheIordache Eduard EdyIordache Data 18 noiembrie 2023 15:07:27
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

void cmmdc (long long a, long long b, long long &d, long long &x, long long &y) {
    if (b == 0) {
        d = a;
        x = 1;
        y = 0;
    }
    else {
        long long x0, y0;
        cmmdc(b, a % b, d, x0, y0);

        x = y0;
        y = x0 - (a/b) * y0;
    }
}

int main() {
    int t;
    long long a, b, c;

    f>>t;
    for (int i = 1; i <= t; i++) {
        f>>a>>b>>c;

        long long d, x, y;
        cmmdc(a, b, d, x, y);
        if (c % d != 0) g<<0<<" "<<0<<endl;
        else g<<x * (c/d)<<" "<<y * (c/d)<<endl;
    }

    return 0;
}