Count triplets ( a , b , c ) such that a + b , b + c and a + c are all divisible by K | Function to find the quadratic equation whose roots are a and b ; iterate for all triples pairs ( i , j , l ) ; if the condition is satisfied ; Driver code
< ? php function count_triples ( $ n , $ k ) { $ i = 0 ; $ j = 0 ; $ l = 0 ; $ count = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 1 ; $ j <= $ n ; $ j ++ ) { for ( $ l = 1 ; $ l <= $ n ; $ l ++ ) { if ( ( $ i + $ j ) % $ k == 0 && ( $ i + $ l ) % $ k == 0 && ( $ j + $ l ) % $ k == 0 ) $ count ++ ; } } } return $ count ; } $ n = 3 ; $ k = 2 ; $ ans = count_triples ( $ n , $ k ) ; echo ( $ ans ) ; ? >