Pagini recente » Cod sursa (job #1226339) | Cod sursa (job #2663804) | Cod sursa (job #522632) | Cod sursa (job #3160330) | Cod sursa (job #1545767)
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a,int b){
int c;
while(b!=0){
c=b;
b=a%b;
a=c;}
return a;
}
void euclid(int a, int b, int &d, int &x, int &y)
{
if (b == 0) {
d = a;
x = 1;
y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
fstream f,g;
f.open("euclid3.in",ios::in);
g.open("euclid3.out",ios::out);
int a,b,c,t,x,y,d,i;
f>>t;
for(i=1;i<=t;i++)
{
x=0;
y=0;
f>>a>>b>>c;
d=cmmdc(a,b);
if(c%d!=0) g<<x<<" "<<y<<'\n';
else {
euclid(a,b,d,x,y);
g<<x<<" "<<y<<'\n';
}
}}