Pagini recente » Cod sursa (job #2901542) | Cod sursa (job #293563) | Cod sursa (job #1896436) | Cod sursa (job #388681) | Cod sursa (job #2750353)
#include <iostream>
#include<fstream>
#include<cmath>
#include<math.h>
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int n;
int x, y;
long long dim;
long long fractal(long long dim, int x,int y)
{
long long lim= sqrt(dim/2);
long long div = dim/2;
if (dim == 1)
return 1;
if (x >= 1 && x <= lim && y >= 1 && y <= lim)
{
swap(x, y);
return fractal(div, x,y);
}
if (x > lim && x <= 2* lim && y >= 1 && y <= lim)
{
x = x % lim;
if (x == 0)
x = lim;
return (div) + fractal(div, x,y);
}
if (x > lim && x <= 2* lim && y > lim && y <= 2* lim)
{
x = x % lim;
if (x == 0)
x = lim;
y = y % lim;
if (y == 0)
y = lim;
return 2*div + fractal(div, x,y);
}
if (x >= 1 && x <= lim && y > lim && y <= 2* lim)
{
y = y % lim;
if (y == 0)
y = lim;
long long a = lim - y + 1;
long long b = lim - x + 1;
x = a;
y = b;
return 3*div + fractal(div, x,y);
}
}
int main()
{
f >> n >> y >> x;
dim = (1 << (n << 1));
g << fractal(dim,x,y) - 1;
return 0;
}