Number of solutions for the equation x + y + z <= n | function to find the number of solutions for the equation x + y + z <= n , such that 0 <= x <= X , 0 <= y <= Y , 0 <= z <= Z . ; to store answer ; for values of x ; for values of y ; maximum possible value of z ; if z value greater than equals to 0 then only it is valid ; find minimum of temp and z ; return required answer ; Driver code
def NumberOfSolutions ( x , y , z , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( x + 1 ) : NEW_LINE INDENT for j in range ( y + 1 ) : NEW_LINE INDENT temp = n - i - j NEW_LINE if temp >= 0 : NEW_LINE INDENT temp = min ( temp , z ) NEW_LINE ans += temp + 1 NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x , y , z , n = 1 , 2 , 3 , 4 NEW_LINE print ( NumberOfSolutions ( x , y , z , n ) ) NEW_LINE DEDENT