Count Pronic numbers from a given range | Python3 program for the above approach ; Function to check if x is a Pronic Number or not ; Check for Pronic Number by multiplying consecutive numbers ; Function to count pronic numbers in the range [ A , B ] ; Initialise count ; Iterate from A to B ; If i is pronic ; Increment count ; Prcount ; Driver Code ; Function call to count pronic numbers in the range [ A , B ]
import math NEW_LINE def checkPronic ( x ) : NEW_LINE INDENT for i in range ( int ( math . sqrt ( x ) ) + 1 ) : NEW_LINE INDENT if ( x == i * ( i + 1 ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def countPronic ( A , B ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( A , B + 1 ) : NEW_LINE INDENT if ( checkPronic ( i ) != 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE DEDENT A = 3 NEW_LINE B = 20 NEW_LINE countPronic ( A , B ) NEW_LINE