Count Pronic numbers from a given range | Function to count pronic numbers in the range [ A , B ] ; Check upto sqrt N ; If product of consecutive numbers are less than equal to num ; Return N - 1 ; Function to count pronic numbers in the range [ A , B ] ; Subtract the count of pronic numbers which are <= ( A - 1 ) from the count f pronic numbers which are <= B ; Driver Code ; Function call to count pronic numbers in the range [ A , B ]
function pronic ( num ) { var N = parseInt ( Math . sqrt ( num ) ) ; if ( N * ( N + 1 ) <= num ) { return N ; } return N - 1 ; } function countPronic ( A , B ) { return pronic ( B ) - pronic ( A - 1 ) ; } var A = 3 ; var B = 20 ; document . write ( countPronic ( A , B ) ) ;