# Cod sursa(job #2739581)

Utilizator Data 8 aprilie 2021 20:47:33 Fractal 0 cpp-64 done Arhiva de probleme 1.32 kb
``````#include <iostream>
#include<fstream>
#define x first
#define y second
using namespace std;
ifstream f("fractal.in");
ofstream g("fractal.out");
int n;
pair<int, int> dest;
int dim;

int fractal(int dim, pair<int, int>& p)
{
if (dim == 1)
return 1;
if (p.x >= 1 && p.x <= sqrt(dim / 4) && p.y >= 1 && p.y <= sqrt(dim / 4))
{
swap(p.x, p.y);
return fractal(dim / 4, p);
}
if (p.x > sqrt(dim / 4) && p.x <= 2* sqrt(dim / 4) && p.y >= 1 && p.y <= sqrt(dim / 4))
{

p.x = p.x % int(sqrt(dim / 4));
if (p.x == 0)
p.x = sqrt(dim / 4);
return (dim / 4) + fractal(dim / 4, p);

}
if (p.x > sqrt(dim / 4) && p.x <= 2* sqrt(dim / 4) && p.y > sqrt(dim / 4) && p.y <= 2* sqrt(dim / 4))
{
p.x = p.x % int(sqrt(dim / 4));
if (p.x == 0)
p.x = sqrt(dim / 4);
p.y = p.y % int(sqrt(dim / 4));
if (p.y == 0)
p.y = sqrt(dim / 4);

return 2*(dim / 4) + fractal(dim / 4, p);

}

if (p.x >= 1 && p.x <= sqrt(dim / 4) && p.y > sqrt(dim / 4) && p.y <= 2* sqrt(dim / 4))
{
p.y =p.y % int(sqrt(dim/4));
if (p.y == 0)
p.y = sqrt(dim / 4);

p.x = sqrt(dim / 4) - p.y + 1;
p.y = sqrt(dim / 4) - p.x + 1;
return  3*(dim / 4) + fractal(dim / 4, p);

}
}

int main()
{
f >> n >> dest.y >> dest.x;
dim = pow(2, n);
g << fractal(dim * dim, dest) - 1;
return 0;
}
``````