Count number of triplets with product not exceeding a given number | Function to count the number of triplets whose product is at most N ; Stores the count of triplets ; Iterate over the range [ 0 , N ] ; Iterate over the range [ 0 , N ] ; If the product of pairs exceeds N ; Increment the count of possible triplets ; Return the total count ; Driver Code
function countTriplets ( N ) { let ans = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= N ; j ++ ) { if ( i * j > N ) break ; ans += Math . floor ( N / ( i * j ) ) ; } } return ans ; } let N = 10 ; document . write ( countTriplets ( N ) ) ;