Count pair sums that are factors of the sum of the array

Count pair sums that are factors of the sum of the arrayGiven an array arr[] consisting of N integers, the task is to find the number of pairs, where i ≤ j, such that the sum of pairs divides the sum of array elements.Examples:Input: arr[] = {1, 2, 3, 4, 5}Output: 3Explanation:Below are the pairs that divides the sum of array( = 1 + 2 + 3 + 4 + 5 = 15):(1, 2): Sum of pairs = 1 + 2 = 3, that divides sum(= 15).(1, 4): Sum of pairs = 1 + 4 = 5, that divides sum(= 15).(2, 3): Sum of pairs = 2 + 3 = 5, that divides sum(= 15).Therefore, the count of pairs is 3.Input: arr[] = {1, 5, 2}Output: 0Approach: The given problem can be solved by generating all possible pairs (arr[i], arr[j]) from the given array such that i ≤  j and count all those pairs whose sum of elements divides the sum of the array. After checking for all possible pairs, print the total count obtained.Below is the implementation of the above approach.C++  #include using namespace std;  void countPairs(int arr[], int N){            int count = 0, totalSum = 0;          for (int i = 0; i < N; i++) {        totalSum += arr[i];    }          for (int i = 0; i < N; i++) {          for (int j = i + 1; j < N; j++) {                                      if (totalSum                    % (arr[i] + arr[j])                == 0) {                                  count += 1;            }        }    }          cout