Pagini recente » Cod sursa (job #2664765) | Cod sursa (job #451865) | Cod sursa (job #337578) | Cod sursa (job #23241) | Cod sursa (job #2635857)
#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);
int r=c/d;
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)*r)%a==0)
{
x = (d-i)*r/a;
y = (c-(d-i)*r)/b;
if(x<2000000000&&y<2000000000&&x>-2000000000&&y>-2000000000)
return;
}
for(long long i=b; i > -2000000000; i-=b)
if(((d-i)*r)%a==0)
{
x = (d-i)*r/a;
y = (c-(d-i)*r)/b;
if(x<2000000000&&y<2000000000&&x>-2000000000&&y>-2000000000)
return;
}
x=y=69;
/*{
*x = (double)(d-i)/a * c/d;
cout<<*x<<endl;
if(*x==(long long)*x)
break;
}*/
}
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;
}