Pagini recente » Cod sursa (job #715723) | Cod sursa (job #2301268) | Cod sursa (job #1096433) | Cod sursa (job #697202) | Cod sursa (job #460002)
Cod sursa(job #460002)
#include <stdio.h>
int f(int k,int x,int y)
{if(k==1)
{ if(x==1)
{ if(y==1)
{ return 0;
}
else
{ return 3;
}
}
else
{ if(y==1)
{ return 1;
}
else
{ return 2;
}
}
}
int p;
p=1<<(k-1);
if(x>p)
{if(y>p)
{return 2*p*p+f(--k,x-p,y-p);
}
else
{return 3*p*p+f(--k,y,2*p-x);
}
}
else
{if(y>p)
{return p*p+f(--k,x,y-p);
}
else
{return f(--k,y,x);
}
}
}
int main ()
{freopen("fractal.in","r",stdin);
freopen("fractal.out","w",stdout);
int k,x,y;
scanf("%d %d %d",&k,&x,&y);
printf("%d ", f(k,x,y));
return 0;
}