Hi, I’m wondering how to compute the following sum efficiently (N<10^6).

For given arrays a and b of length N let f(a,b)=(\sum_{i=0}^{N-1}(b_i-a_i)2^i)\cdot\frac{1}{1-2^N} This is needed for one solution of the JOI 2019 problem Remittance. I’ve read the editorial which states the use of precision integers could be handy, but I’m still having a tought time getting my head around it. Any help is appreciated! Thanks

Also, please explain why the provided solution works and not just give the code.