Cod sursa(job #2471182)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 10 octombrie 2019 15:52:53
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

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);
    y = x1 - (a / b) * y1;
    x = y1;
    return d;
}

int main()
{
    ios::sync_with_stdio(false);
    fin.tie(0);

    long long tt;
    fin >> tt;
    while(tt--) {
        long long a, b, c;
        fin >> a >> b >> c;
        long long x = 0, y = 0;
        long long cmmdc = gcd(a, b, x, y);
        if(c % cmmdc == 0) {
            fout << x * (c / cmmdc) << " " << y * (c / cmmdc) << "\n";
        }
        else fout << "0" << " " << "0" << "\n";
    }
    return 0;
}