Cod sursa(job #2141924)

Utilizator Evrika12Mihnea Rontescu Evrika12 Data 24 februarie 2018 17:17:35
Problema Evaluarea unei expresii Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
#define N_MAX 1 << 30

using namespace std;

ifstream cin ("tabela.in") ;
ofstream cout ("tabela.out") ;

int z(int l, int c, int s, int n) {
    if (n == 0)
        return l - 1 ;
    if (c <= n) {
        if (l <= s + n)
            return z(l, c, s, n >> 1);
        else
            return z(l, c, s + n, n >> 1);
    }
    else {
        if (l <= s + n)
            return z(s + c, l - s, s + n, n >> 1);
        else
            return z(s + (n << 1) - c + 1, s + (n << 1) - l + 1, s, n >> 1);
    }
}

int main() {
    int n, m;
    cin >> n >> m ;
    cout << z(n, m, 0, N_MAX);
    return 0;
}