Check if a given integer is the product of K consecutive integers | Function to check if N can be expressed as the product of K consecutive integers ; Stores the K - th root of N ; Stores the product of K consecutive integers ; Traverse over the range [ 1 , K ] ; Update the product ; If product is N , then return " Yes " ; Otherwise , traverse over the range [ 2 , Kthroot ] ; Update the value of product ; If product is equal to N ; Otherwise , return " No " ; Driver Code
def checkPro ( n , k ) : NEW_LINE INDENT KthRoot = int ( n ** ( 1 / k ) ) NEW_LINE product = 1 NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT product = product * i NEW_LINE DEDENT print ( product ) NEW_LINE if ( product == N ) : NEW_LINE INDENT return ( " Yes " ) NEW_LINE DEDENT for i in range ( 2 , KthRoot + 1 ) : NEW_LINE INDENT product = product * ( i + k - 1 ) NEW_LINE product = product / ( i - 1 ) NEW_LINE print ( product ) NEW_LINE if ( product == N ) : NEW_LINE INDENT return ( " Yes " ) NEW_LINE DEDENT DEDENT return ( " No " ) NEW_LINE DEDENT N = 210 NEW_LINE K = 3 NEW_LINE print ( checkPro ( N , K ) ) NEW_LINE