Count triplets such that product of two numbers added with third number is N | Function to find the divisors of the number ( N - i ) ; Stores the resultant count of divisors of ( N - i ) ; Iterate over range [ 1 , sqrt ( N ) ] ; Return the total divisors ; Function to find the number of triplets such that A * B - C = N ; Loop to fix the value of C ; Adding the number of divisors in count ; Return count of triplets ; Driver Code
function countDivisors ( n ) { var divisors = 0 ; var i ; for ( i = 1 ; i * i < n ; i ++ ) { if ( n % i == 0 ) { divisors ++ ; } } if ( i - ( n / i ) == 1 ) { i -- ; } for ( ; i >= 1 ; i -- ) { if ( n % i == 0 ) { divisors ++ ; } } return divisors ; } function possibleTriplets ( N ) { var count = 0 ; for ( var i = 1 ; i < N ; i ++ ) { count += countDivisors ( N - i ) ; } return count ; } var N = 10 ; document . write ( possibleTriplets ( N ) ) ;