In the above implementation we have considered every pair two times so we have to divide every sum2 array element by 2
for ( $ i = 1 ; $ i < $ max_Element ; $ i ++ ) $ sum2 [ $ i ] = ( int ) ( $ sum2 [ $ i ] / 2 ) ;