Count of triplets till N whose product is at most N | Function to find number of triplets ( A , B , C ) having A * B * C <= N ; Stores the count of triplets ; Iterate a loop fixing the value of A ; Iterate a loop fixing the value of A ; Find the total count of triplets and add it to cnt ; Return the total triplets formed ; Driver Code
def countTriplets ( N ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE for A in range ( 1 , N + 1 ) : NEW_LINE INDENT for B in range ( 1 , N // A + 1 ) : NEW_LINE INDENT cnt += N // ( A * B ) ; NEW_LINE DEDENT DEDENT return cnt ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 2 ; NEW_LINE print ( countTriplets ( N ) ) ; NEW_LINE DEDENT