Cod sursa(job #1501825)

Utilizator ili226Vlad Ilie ili226 Data 13 octombrie 2015 21:10:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.74 kb
var i,t:byte;
    f,fo:text;
    x,y,a,b,c,d:longint;
procedure euclid(a,b:longint;var d,x,y:longint);
var x0,y0:longint;
begin 
 if b=0 then 
  begin
   d:=a;
   x:=1;
   y:=0
  end
	else
  begin
   euclid(b,a mod b,d,x0,y0);
   x:=y0;
   y:=x0-(a div b)*y0
  end;
end;
begin
assign(f,'euclid3.in');
assign(fo,'euclid3.out');
reset(f);
rewrite(fo);
readln(f,t);
for i:=1 to t do
 begin 
  readln(f,a,b,c);
  euclid(a,b,d,x,y);
  if c mod d=0 then 
   begin
    x:=x*(c div d);
    y:=y*(c div d);
    writeln(fo,x,' ',y);
   end	
	       else
   if d mod c =0 then
    begin
     x:=x*(d div c);
     y:=y*(d div c);
     writeln(fo,x,' ',y);
    end	
		else
   writeln(fo,'0 0');	
 end;
close(fo);
close(f);
end.