Compute all-pairs distance correlation efficiently using matrix multiplications. Uses n^2M memory.