updated algorithm for cube summation