Cod sursa(job #3291943)

Utilizator Alex_DumitrascuAlex Dumitrascu Alex_Dumitrascu Data 6 aprilie 2025 12:56:42
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
/*
24x + 18y = 6
18x + 6y= 6
6x + 0y = 0
*/
ll gcd (ll a, ll b, ll &x, ll &y) {
    if (b==0) {
        x=1; y=0;
        // cout<<a<<'*'<<x<<'+'<<b<<'*'<<y<<'='<<a<<endl;
        return a;
    }
    else {
        ll x1, y1;
        ll d = gcd(b, a % b, x1, y1);
        x = y1;
        y = x1 - y1 * (a / b);
        // cout<<a<<'*'<<x<<'+'<<b<<'*'<<y<<'='<<d<<endl;
        return d;
    }
}

int main()
{
    fin.tie(0); fin.sync_with_stdio(false);
    ll t; fin>>t;
    while (t--) {
        ll a, b, c; fin>>a>>b>>c;
        ll x, y; ll d = gcd(a, b, x, y);
        // cout<<endl;
        ll rap = c / d;
        if ((float)c/d!=rap) {
            fout<<"0 0\n";
            continue;
        }
        else {
            x*=rap; y*=rap;
            fout<<x<<' '<<y<<'\n';
        }
    }
    return 0;
}