Cod sursa(job #3348318)

Utilizator andreigeorgedutaDuta Andrei-George andreigeorgeduta Data 20 martie 2026 19:03:26
Problema Fractal Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <stdio.h>

unsigned long long functie(int ordin_crt, int a, int b){
   if( ordin_crt == 0) return 0;
   unsigned long long L = 1LL << (ordin_crt - 1);
   unsigned long long pasi_crt = L * L;
   if( a <= L && b <= L ) return functie(ordin_crt - 1, b, a);
   if( a <= L && b > L ) return pasi_crt + functie(ordin_crt - 1, a, b - L);
   if( a > L && b > L ) return 2 * pasi_crt + functie(ordin_crt - 1, a - L, b - L);
      return 3 * pasi_crt + functie(ordin_crt - 1, L - b + 1, 2 * L - a + 1); 
}

int main(){
    
    FILE* fin = fopen("fractal.in", "r");
    FILE* fout = fopen("fractal.out", "w");
    int k, x, y;
    fscanf(fin, "%d %d %d", &k, &x, &y);
    unsigned long long pasi = functie(k, x, y);
    fprintf(fout, "%llu", pasi);
    return 0;
}