Count number of triplets ( a , b , c ) from first N natural numbers such that a * b + c = N | Function to find the count of triplets ( a , b , c ) with a * b + c = N ; Stores count of triplets of 1 st N natural numbers which are of the form a * b + c = N ; Iterate over the range [ 1 , N ] ; If N is divisible by i ; Update cntTriplet ; Update cntTriplet ; Driver Code
function findCntTriplet ( N ) { let cntTriplet = 0 ; for ( let i = 1 ; i < N ; i ++ ) { if ( N % i != 0 ) { cntTriplet += Math . floor ( N / i ) ; } else { cntTriplet += Math . floor ( N / i ) - 1 ; } } return cntTriplet ; } let N = 3 ; document . write ( findCntTriplet ( N ) ) ;