Number of subarrays consisting only of Pronic Numbers | Function to check if a number is pronic number or not ; Iterate over the range [ 1 , sqrt ( N ) ] ; Return true if N is pronic ; Otherwise , return false ; Function to count the number of subarrays consisting of pronic numbers ; Stores the count of subarrays ; Stores the number of consecutive array elements which are pronic ; Traverse the array ; If i is pronic ; Return the total count ; Driver Code
def isPronic ( n ) : NEW_LINE INDENT for i in range ( int ( n ** ( 1 / 2 ) ) + 1 ) : NEW_LINE INDENT if i * ( i + 1 ) == n : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def countSub ( arr ) : NEW_LINE INDENT ans = 0 NEW_LINE ispro = 0 NEW_LINE for i in arr : NEW_LINE INDENT if isPronic ( i ) : NEW_LINE INDENT ispro += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ispro = 0 NEW_LINE DEDENT ans += ispro NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 5 , 6 , 12 , 3 , 4 ] NEW_LINE print ( countSub ( arr ) ) NEW_LINE