Cod sursa(job #3132771)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 23 mai 2023 20:54:51
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("fractal.in");
ofstream fout("fractal.out");
int a, b, k;

int Hilbert(int k, int a, int b) {
    int r = 0;
    for(int i = k / 2; i; i /= 2) {
        bool ra = (a & i);
        bool rb = (b & i);

        r += i * i * ((3 * ra) ^ rb);
        
        if(!rb) {
	    if(ra) {
		a = k - a - 1;
		b = k - b - 1;
	    }
	    swap(a, b);
 	}
    }

    return r;
}

int main() {
    fin >> k >> a >> b;
    fout << Hilbert((1 << k), a - 1, b - 1) << '\n';
    return 0;
}