Count triplets such that product of two numbers added with third number is N | Python program for the above approach ; 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 ; def 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 Driver Code
import math NEW_LINE def countDivisors ( n ) : NEW_LINE INDENT divisors = 0 NEW_LINE for i in range ( 1 , math . ceil ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT divisors = divisors + 1 NEW_LINE DEDENT if ( i - ( n / i ) == 1 ) : NEW_LINE INDENT i = i - 1 NEW_LINE DEDENT DEDENT for i in range ( math . ceil ( math . sqrt ( n ) ) + 1 , 1 , - 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT divisors = divisors + 1 NEW_LINE DEDENT DEDENT return divisors NEW_LINE DEDENT def possibleTriplets ( N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT count = count + countDivisors ( N - i ) NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 10 NEW_LINE print ( possibleTriplets ( N ) ) NEW_LINE DEDENT