Problem #285
Xor Tree
You are given a rooted tree with 2^N nodes numbered from 0 to 2^N - 1. It is rooted at node 0. For all other nodes i, their parent is node j such that j<i and (i ^ j) is minimised, where ^ denotes the bitwise XOR operator .
For example, parent of node 3 will be node 2 as:
3 ^ 0 = 3
3 ^ 1 = 2
3 ^ 2 = 1
Let f(N) be the sum of all pairwise distances modulo 10^9+7 for a tree with 2^N nodes, where distance between two nodes in a tree is defined as the number of edges in the shortest path between them..
f(1) = 1
f(2) = 10
Find f(1234567654321).