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
function checkPro ( n , k ) { var exp = 1.0 / k ; var KthRoot = parseInt ( Math . pow ( n , exp ) ) ; var product = 1 ; for ( i = 1 ; i < k + 1 ; i ++ ) { product = product * i ; } if ( product == n ) return " " ; else { for ( j = 2 ; j < KthRoot + 1 ; j ++ ) { product = product * ( j + k - 1 ) ; product = product / ( j - 1 ) ; if ( product == n ) return " " ; } } return " " ; } var N = 210 ; var K = 3 ; document . write ( checkPro ( N , K ) ) ;