Count pair sums that are factors of the sum of the array | Function to find the number of pairs whose sums divides the sum of array ; Initialize the totalSum and count as 0 ; Calculate the total sum of array ; Generate all possible pairs ; If the sum is a factor of totalSum or not ; Increment count by 1 ; Print the total count obtained ; Driver Code
function countPairs ( arr , N ) { let count = 0 , totalSum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( totalSum % ( arr [ i ] + arr [ j ] ) == 0 ) { count += 1 ; } } } document . write ( count ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; countPairs ( arr , N ) ;