uses Crt;
const
 n=20;
var
 a,b,x : 0..(10000 div 2);
 af,bf,sf,frow : array[0..n+1] of integer;
 i : integer;
{---------------------------------------------------------------------------}
function check(sf : array of integer) : boolean; forward;
{---------------------------------------------------------------------------}
 function convert(num : LongInt): integer;
  var
   j : integer;
  begin
   for j:=1 to n do
    begin
     if frow[j]>num then begin convert:=j-1;  exit; end;
     if frow[j]=num then begin convert:=j;  exit; end;
    end;
  end;
{---------------------------------------------------------------------------}
procedure sum(sf : array of integer);
begin
 repeat
  for i:=1 to n do
   begin
    if (sf[i]>=1) and (sf[i-1]>=1) then begin INC(sf[i+1]); DEC(sf[i]); DEC(sf[i-1]); end;
    if (sf[i]>1) and (i>1) then begin INC(sf[i+1]); INC(sf[i-2]); sf[i]:=sf[i]-2; end;
    if sf[0]>=1 then begin sf[1]:=sf[1]+sf[0]; sf[0]:=0; end;
    sf[2]:=sf[2]+sf[1] div 2; sf[1]:=sf[1] mod 2;
   end;
 until check(sf);
 WriteLn(' "Фиббоначиева" сумма чисел ',a,' и ',b,' равна ' );
 for i:=n downto 1 do Write(sf[i]); WriteLn;
end;
{---------------------------------------------------------------------------}
 function check(sf : array of integer) : boolean;
var
 flag : boolean;
begin
 flag:=true;
 for i:=1 to n do
  if (sf[i]>1) or ((sf[i]>=1) and (sf[i-1]>=1)) then begin flag:=false; break; end;
 check:=flag;
end;
{---------------------------------------------------------------------------}
begin
 WriteLn('Введите два числа');
 Read(a,b);
 if a*b=0 then begin WriteLn('Сам ты ноль!'); ReadLn; exit; end;
 frow[1]:=1; frow[2]:=2;
 for i:=1 to n do
  begin
   af[i]:=0; bf[i]:=0; sf[i]:=0;
   if i<=n-2 then frow[i+2]:=frow[i+1]+frow[i];
  end;
 x:=a; repeat INC(af[convert(x)]); x:=x-frow[convert(x)]; until x=0;
 x:=b; repeat INC(bf[convert(x)]); x:=x-frow[convert(x)]; until x=0;
 for i:=1 to n do sf[i]:=af[i]+bf[i];
 WriteLn(' "Фиббоначиева" форма числа ',a,' равна ' );
 for i:=n downto 1 do Write(af[i]); WriteLn;
 WriteLn(' "Фиббоначиева" форма числа ',b,' равна ' );
 for i:=n downto 1 do Write(bf[i]); WriteLn;
 sum(sf);
 for i:=1 to n do bf[i]:=0;
 x:=a+b; repeat INC(bf[convert(x)]); x:=x-frow[convert(x)]; until x=0;
 WriteLn('Контроль : ');
 for i:=n downto 1 do Write(bf[i]); WriteLn;
 WriteLn('А реально их сумма равна ',(a+b));
 ReadLn;
 ReadLn;
end.