function [ d,x,y ] = bezout( a,b )
% function [ d,x,y ] = bezout( a,b )
% Reseni rovnice ax+by=d
% d=NSD(a,b)
% 
a1=1;a2=0;
b1=0;b2=1;
y0=a;
y1=b;
y2=mod(y0,y1);
while y2~=0
    a0=a1;a1=a2;
    b0=b1;b1=b2;
    q=(y0-y2)/y1;
    a2=a0-q*a1;
    b2=b0-q*b1;
    y0=y1;y1=y2;
    y2=mod(y0,y1);
end
if y1<0
    d=-y1;x=-a2;y=-b2;
else
    d=y1;x=a2;y=b2;
end
end

