Count all subarrays whose sum can be split as difference of squares of two Integers | C ++ program to count all the non - contiguous subarrays whose sum can be split as the difference of the squares ; Function to count all the non - contiguous subarrays whose sum can be split as the difference of the squares ; Loop to iterate over all the possible subsequences of the array ; Finding the sum of all the possible subsequences ; Condition to check whether the number can be split as difference of squares ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Solve ( int arr [ ] , int n ) { int temp = 0 , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { temp = 0 ; for ( int j = i ; j < n ; j ++ ) { temp += arr [ j ] ; if ( ( temp + 2 ) % 4 != 0 ) count ++ ; } } return count ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int N = sizeof ( arr ) / sizeof ( int ) ; cout << Solve ( arr , N ) ; return 0 ; }