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
function count_triples ( n , k ) { var i = 0 , j = 0 , l = 0 ; var 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 ; } var n = 3 ; var k = 2 ; var ans = count_triples ( n , k ) ; document . write ( ans ) ;