Subsequences of size three in an array whose sum is divisible by m | Brute Force Implementation ( Time Complexity : O ( N ^ 3 ) ) PHP program to find count of subsequences of size three divisible by M . ; Three nested loop to find all the sub sequences of length three in the given array A [ ] . ; checking if the sum of the chosen three number is divisible by m . ; Driver code
< ? php function coutSubSeq ( $ A , $ N , $ M ) { $ sum = 0 ; $ ans = 0 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = $ i + 1 ; $ j < $ N ; $ j ++ ) { for ( $ k = $ j + 1 ; $ k < $ N ; $ k ++ ) { $ sum = $ A [ $ i ] + $ A [ $ j ] + $ A [ $ k ] ; if ( $ sum % $ M == 0 ) $ ans ++ ; } } } return $ ans ; } $ M = 3 ; $ A = array ( 1 , 2 , 4 , 3 ) ; $ N = count ( $ A ) ; echo coutSubSeq ( $ A , $ N , $ M ) ; ? >