Pagini recente » Cod sursa (job #3278153) | Cod sursa (job #3276135) | Cod sursa (job #3175662) | Cod sursa (job #3276284) | Cod sursa (job #3256781)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
typedef long long ll;
typedef pair<ll,ll> pll;
ll t;
ll cmmdc(ll a,ll b)
{
if(a==0)
return b;
if(b==0)
return a;
while(b)
{
ll r=a%b;
a=b;
b=r;
}
return a;
}
pll solve(ll a,ll b,ll c)
{
ll g=cmmdc(a,b);
if(a==0&&b==0)
return {0,0};
if(c%g!=0)
return {0,0};
a/=g;
b/=g;
c/=g;
pll Va={1,0};
pll Vb={0,1};
while(b!=0)
{
ll cat=a/b;
ll rest=a%b;
pll Vr;
Vr.first=Va.first-Vb.first*cat;
Vr.second=Va.second-Vb.second*cat;
Va=Vb;
Vb=Vr;
a=b;
b=rest;
}
return {Va.first*c,Va.second*c};
}
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>t;
while(t--)
{
ll a,b,c;
fin>>a>>b>>c;
pll x=solve(a,b,c);
fout<<x.first<<' '<<x.second<<'\n';
}
return 0;
}