Cod sursa(job #1865457)

Utilizator msciSergiu Marin msci Data 1 februarie 2017 19:29:42
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <tuple>
#include <limits>
#include <functional>
#include <complex>
#include <bitset>
#include <list>

//#include <atomic>
//#include <condition_variable>
//#include <future>
//#include <mutex>
//#include <thread>

using namespace std;

#define debug(x) cerr << #x << " = " << x << "\n"

int extended_euclid(int a, int b, int& x, int& y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    int x0, y0;
    int d = extended_euclid(b % a, a, x0, y0);
    x = y0 - (b / a) * x0;
    y = x0;
    return d;
}

int main(int argc, char* argv[]) 
{
#ifndef LOCAL
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
#endif
    cin.sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        int x, y;
        int d = extended_euclid(a, b, x, y);
        if (c % d) cout << "0 0\n";
        else cout << x * (c / d) << " " << y * (c / d) << "\n";
    }
    return 0;
}