Cod sursa(job #2664876)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 29 octombrie 2020 17:23:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.46 kb
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
ll t,a,b,c;
void solve()
{
    fin>>a>>b>>c;
    ll d=__gcd(a,b);
    if(c%d!=0)
    {
        fout<<"0 0\n";
        return;
    }
    c/=d;
    a/=d;
    b/=d;
    pll Va={1,0};
    pll Vb={0,1};
    pll Vr={0,0};
    while(b)
    {
        ll r=a%b;
        ll cat=a/b;
        Vr.first=Va.first-cat*Vb.first;
        Vr.second=Va.second-cat*Vb.second;
        a=b;
        b=r;
        Va=Vb;
        Vb=Vr;
    }
    fout<<Va.first*c<<" "<<Va.second*c<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);
    fout.tie(0);
    fin>>t;
    while(t--)
        solve();
    return 0;
}