Count triplets ( a , b , c ) such that a + b , b + c and a + c are all divisible by K | ''Function returns the  count of the triplets ; Iterate for all triples pairs ( i , j , l ) ; If the condition is satisfied ; Driver code
def count_triples ( n , k ) : NEW_LINE INDENT count , i , j , l = 0 , 0 , 0 , 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT for l in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( ( i + j ) % k == 0 and ( i + l ) % k == 0 and ( j + l ) % k == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , k = 3 , 2 NEW_LINE ans = count_triples ( n , k ) NEW_LINE print ( ans ) NEW_LINE DEDENT