Pagini recente » Cod sursa (job #499599) | Cod sursa (job #1466332) | Cod sursa (job #1564072) | Cod sursa (job #2375318) | Cod sursa (job #3227604)
//https://infoarena.ro/problema/euclid3
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin( "euclid3.in");
ofstream fout( "euclid3.out");
void euclid_extins(int a, int b, int *d, int *x, int *y)
{
int x1=0, y1=0;
if (b == 0)
{
*d = a;
*x = 1;
*y = 0;
}
else
{
euclid_extins(b, a % b, d, &x1, &y1);
*x = y1;
*y = x1 - (a/b)*y1;
}
}
int main()
{
int a, b, c, nr,i=0;
cout<<"DA";
fin>>nr;
for(i=1; i<=nr; i++)
{
fin>>a>>b>>c;
int d, x, y;
euclid_extins(a, b, &d, &x, &y);
if (c%d != 0)
fout<<"0 0\n";
else
fout<<(c/d*x)<<" "<<(c/d*y)<<"\n";
}
return 0;
}