C# Ladder
static int[] Ladder(int[] a, int[] b)
{
var size = a.Length;
var r = new int[size];
var mod = (1 << b.Max()) - 1;
var limit = a.Max();
var fib = new int[limit + 2];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i < limit + 2; i++)
{
fib[i] = (fib[i - 1] + fib[i - 2]) & mod;
}
for (int i = 0; i < size; i++)
{
r[i] = fib[a[i] + 1] & ((1 << b[i]) - 1);
}
return r;
}
This precomputes climb counts once and applies the modulo per query, which avoids recalculating the same paths over and over.