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 ]
def pronic ( num ) : NEW_LINE INDENT N = int ( num ** ( 1 / 2 ) ) ; NEW_LINE if ( N * ( N + 1 ) <= num ) : NEW_LINE INDENT return N ; NEW_LINE DEDENT return N - 1 ; NEW_LINE DEDENT def countPronic ( A , B ) : NEW_LINE INDENT return pronic ( B ) - pronic ( A - 1 ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = 3 ; NEW_LINE B = 20 ; NEW_LINE print ( countPronic ( A , B ) ) ; NEW_LINE DEDENT