Count of subsequences whose product is a difference of square of two integers | C # implementation to count the number of contiguous subsequences whose product can be expressed as the square of difference of two integers ; Function to count the number of contiguous subsequences whose product can be expressed as square of difference of two integers ; Iterating through the array ; Check if that number can be expressed as the square of difference of two numbers ; Variable to compute the product ; Finding the remaining subsequences ; Check if that number can be expressed as the square of difference of two numbers ; Return the number of subsequences ; Driver code
using System ; class GFG { static int CntcontSubs ( int [ ] a , int n ) { int c = 0 , d = 0 , i , sum = 1 , j ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 != 0 a [ i ] % 4 == 0 ) d ++ ; sum = a [ i ] ; for ( j = i + 1 ; j < n ; j ++ ) { sum = sum * a [ j ] ; if ( sum % 2 != 0 sum % 4 == 0 ) c ++ ; } sum = 1 ; } return c + d ; } static void Main ( ) { int [ ] arr = { 5 , 4 , 2 , 9 , 8 } ; int n = arr . Length ; Console . Write ( CntcontSubs ( arr , n ) ) ; } }