Pagini recente » Cod sursa (job #142550) | Cod sursa (job #971559) | Cod sursa (job #584617) | Cod sursa (job #57302) | Cod sursa (job #612846)
Cod sursa(job #612846)
#include <stdio.h>
#include <math.h>
long K, X, Y, rez, tot;
void go(long K, long X, long Y) {
if (K == 0) {
return;
}
long put = 1 << (K - 1);
if (X <= put && put >= Y) go(K - 1, Y, X);
if (X <= put && put < Y) {
tot += 3 * put * put;
go(K - 1, 2 * put - Y + 1, put - X + 1);
}
if (X > put && put >= Y) {
tot += put * put;
go(K - 1, X - put, Y);
}
if (X > put && put < Y) {
tot += put * put * 2;
go(K - 1, X - put, Y - put);
}
}
int main() {
freopen("fractal.in", "r", stdin);
freopen("fractal.out", "w", stdout);
scanf("%ld %ld %ld", &K, &X, &Y);
go(K, Y, X);
printf("%ld\n", tot);
return 0;
}