Problem . For N three-dimensional points, which are {$ p_1, p_2, .., p_n $}, where $ p_i = (x_i, y_i, z_i) $. I have to find the value of the formula

for some given constant integers P, Q, R, S. all numbers are between 1 and M (= 100).
I need an efficient method to calculate this formula
Please give an idea of how to reduce complexity better than $ O (n ^ 2) $
source
share