Cod sursa(job #1999)

Utilizator kimhioCobarzan Petrut kimhio Data 15 decembrie 2006 17:00:51
Problema Fractal Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.93 kb
program fractal;
type ta=array [0..20] of int64;


var f:text;
    p,n,x,y,rez:int64;
    a:ta;
    i:longint;



function calcul(k,x,y:longint):int64;
begin
if p>1 then
   begin
   p:=p div 2;
   if (y<=p) and (x<=p) then
      begin
      calcul:=calcul(k-1,y,x);
      exit;
      end;
   if (y>p) and (x<=p) then
      begin
      calcul:=a[k-1]+1+calcul(k-1,x,y-p);
      exit;
      end;
   if (y>p) and (x>p) then
      begin
      calcul:=2*a[k-1]+2+calcul(k-1,x-p,y-p);
      exit;
      end;
   if (y<=p) and (x>p) then
      begin
      calcul:=3*a[k-1]+3+calcul(k-1,p-y+1,p*2-x+1);
      exit;
      end;
   end
   else
   calcul:=0;
end;







begin
assign(f,'fractal.in');reset(f);
read(f,n,x,y);
close(f);
a[0]:=0;
for i:=1 to n do
    a[i]:=a[i-1]*4+3;
p:=1;
for i:=1 to n do
    p:=p*2;
assign(f,'fractal.out');rewrite(f);
rez:=calcul(n,x,y);
write(f,rez);
close(f);
end.