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
function isPronic ( n ) { let range = Math . sqrt ( n ) ; for ( let i = 0 ; i < range + 1 ; i ++ ) { if ( i * ( i + 1 ) == n ) return true ; } return false ; } function countSub ( arr , n ) { let ans = 0 ; let ispro = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPronic ( arr [ i ] ) ) ispro += 1 ; else ispro = 0 ; ans += ispro ; } return ans ; } let arr = [ 5 , 6 , 12 , 3 , 4 ] ; let n = arr . length ; document . write ( countSub ( arr , n ) ) ;