Given N and K. The task is to count the number of the integral solutions of a linear equation having N variable as given below:
x1 + x2+ x3…+ xN-1+…+xN = K
Input: N = 3, K = 3 Output: 10 Input: N = 2, K = 2 Output: 3
Approach: This problem can be solved using the concept of Permutation and Combination. Below are the direct formulas for finding non-negative and positive integral solutions respectively.
Number of non-negative integral solutions of equation x1 + x2 + …… + xn = k is given by (n+k-1)! / (n-1)!*k!.
Number of positive integral solutions of equation x1 + x2 + ….. + xn = k is given by (k-1)! / (n-1)! * (k-n)!.
Below is the implementation of above approach:
Applications of the above concepts:
- Number of non-negative integral solutions of equation x1 + x2 +…+ xn = k is equal to the number of ways in which k identical balls can be distributed into N unique boxes.
- Number of positive integral solutions of equation x1 + x2 + … + xn = k is equal to the number of ways in which k identical balls can be distributed into N unique boxes such that each box must contain at-least 1 ball.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Number of non-negative integral solutions of sum equation
- Number of integral solutions for equation x = b*(sumofdigits(x)^a)+c
- Number of non-negative integral solutions of a + b + c = n
- Number of solutions for the equation x + y + z <= n
- Find the number of solutions to the given equation
- Program to find number of solutions in Quadratic Equation
- Find number of solutions of a linear equation of n variables
- Find the integral roots of a given Cubic equation
- Python | Finding Solutions of a Polynomial Equation
- Find initial integral solution of Linear Diophantine equation if finite solution exists
- Number of solutions of n = x + n ⊕ x
- Number of solutions for x < y, where a <= x <= b and c <= y <= d and x, y are integers
- Count number of solutions of x^2 = 1 (mod p) in given range
- Number of solutions to Modular Equations
- Find 'N' number of solutions with the given inequality equations
- Number of sextuplets (or six values) that satisfy an equation
- Number of Integral Points between Two Points
- Count Integral points inside a Triangle
- Trapezoidal Rule for Approximate Value of Definite Integral
- Find integral points with minimum distance from given set of integers using BFS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.