Cod sursa(job #2855410)

Utilizator LionMan101Achim-Panescu Silvian LionMan101 Data 22 februarie 2022 13:38:37
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.15 kb
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int INF=1e9+7;
const ll INFF=1e18+7;
#define nl '\n'
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char* x) { cout << '\"' << x << '\"'; }
void __print(const string& x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V>& x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cout << '{'; for (auto& i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; }
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

tuple<int, int, int> extendedEuclid(int a, int b)
{
    if (a == 0) return make_tuple(b, 0, 1);
    int gcd, x, y;
    tie(gcd, x, y) = extendedEuclid(b % a, a);
    return make_tuple(gcd, (y - (b/a) * x), x);
}

void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    // debug(a,b,c);
    int gcd,x,y;
    tuple<int,int,int> t=extendedEuclid(a,b);
    tie(gcd,x,y)=t;
    // debug(c,gcd, c%gcd);
    if(c%gcd!=0) cout<<"0 0\n";
    else cout<<x*(c/gcd)<<" "<<y*(c/gcd)<<nl;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t=1;
    int t;
    cin >> t;
    for(int tt=1; tt<=t; tt++){
        // cout<<"#Case "<<t<<nl;
        solve();
    }
    return 0;
}