Pagini recente » Cod sursa (job #1385253) | Cod sursa (job #3256663) | Cod sursa (job #3285268) | Cod sursa (job #3292305) | Cod sursa (job #3244230)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
long long t,i,a,b,c,d,x,y;
void euclid(long long a,long long b, long long &d,long long &x,long long &y)
{
if(b==0)
{
d=a;
x=1,y=1;
}
else
{
long long x1,y1;
euclid(b,a%b,d,x1,y1);
x=y1;
y=x1-a/b*y1;
}
}
int main()
{
fin>>t;
for(i=1;i<=t;i++)
{
fin>>a>>b>>c;
euclid(a,b,d,x,y);
if(c%d)fout<<0<<" "<<0<<'\n';
else
{
long long n=c/d;
x*=n;
y*=n;
if(x>2000000000||y>2000000000)
{
long long g=__gcd(y,x);
fout<<x/g<<" "<<y/g<<'\n';
return 0;
}
fout<<x<<" "<<y<<'\n';
}
}
return 0;
}