Pagini recente » Cod sursa (job #1775518) | Cod sursa (job #3229725) | Cod sursa (job #1639574) | Cod sursa (job #1825567) | Cod sursa (job #2635853)
#include <bits/stdc++.h>
using namespace std;
inline long long Euclid_iter(long long a, long long b)
{
while(b!=0)
{
long long t;
t = a % b;
a = b;
b = t;
}
return a;
}
void Eulid_extins(long long a, long long b, long long c, long long *x, long long *y)
{
long long d=Euclid_iter(a,b);
cout<<d;
if(c%d)
{
*x=0;
*y=0;
return;
}
if(a==0)
{
*y=c/b;
if(c%b==0)
*x=1;
else
{
*x=0;
*y=0;
}
return;
}
if(b==0)
{
*x=c/a;
if(c%a==0)
*y=1;
else
{
*x=0;
*y=0;
}
return;
}
for(long long i=b; i < 2000000000; i+=b)
if(((d-i)*c/d)%a==0)
{
*x = (d-i)*c/d/a;
break;
}
/*{
*x = (double)(d-i)/a * c/d;
cout<<*x<<endl;
if(*x==(long long)*x)
break;
}*/
*y = (c-a*(*x))/b;
}
int main()
{
fstream f("euclid3.in");
ofstream g("euclid3.out");
long long n, a, b, c;
long long x, y;
f>>n;
for(long long i = 0; i < n; i++)
{
f>>a>>b>>c;
Eulid_extins(a, b, c, &x, &y);
g<<(long long)x<<' '<<(long long)y<<'\n';
}
f.close();
g.close();
return 0;
}