Cod sursa(job #3215766)

Utilizator Chris_BlackBlaga Cristian Chris_Black Data 15 martie 2024 12:37:22
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ff first
#define ss second
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FORR(i, a, b) for(int i = a; i >= b; --i)
#define int long long
using namespace std;
const string TASK("euclid3");
ifstream fin(TASK + ".in");
ofstream fout(TASK + ".out");
#define cin fin
#define cout fout

const int N = 2e5 + 9;

int a, b, c;

void euclid(int a, int b, int& x, int& y)
{
    if(!b)x = 1, y = 0;
    else
    {
        int xa, ya;
        euclid(b, a % b, xa, ya);
        x = ya;
        y = xa - ya * (a / b);
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin >> t;
    while(t --)
    {
        cin >> a >> b >> c;
        int g = __gcd(a, b);

        if(c % g != 0)
        {
            cout << "0 0\n";
            continue;
        }

        int x, y;
        euclid(a, b, x, y);

        cout << x * (c / g) << ' ' << y * (c / g) << '\n';
    }
    return 0;
}