Cod sursa(job #2782089)
Utilizator | Ionescu Maria mariaionescu2006 | Data | 11 octombrie 2021 16:52:25 |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.89 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
long long n,i,a,b,cc,t,r,c,j;
struct strstr
{
int a,b,x,y;
}v[10001];
int main()
{
fin>>n;
for (j=1;j<=n;j++)
{fin>>a>>b>>c;
t=1;
v[1].a=a;
v[1].b=b;
while (b!=0)
{r=a%b;
a=b;
b=r;
t++;
v[t].a=a;
v[t].b=b;}
if (c%a==0) {v[t].x=1;
v[t].y=0;
t--;
for (i=t; i>=1; i--)
{cc=v[i].a/v[i].b;
v[i].x=v[i+1].y;
v[i].y=v[i+1].x-cc*v[i+1].y;}
fout<<v[1].x*c/a<<' '<<v[1].y*c/a<<'\n';}
else fout<<0<<' '<<0<<'\n';}
return 0;
}