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
- Find initial integral solution of Linear Diophantine equation if finite solution exists
- Find the integral roots of a given Cubic equation
- Find number of solutions of a linear equation of n variables
- Program to find number of solutions in Quadratic Equation
- Number of solutions for the equation x + y + z <= n
- Find the number of solutions to the given equation
- Python | Finding Solutions of a Polynomial Equation
- Number of Integral Points between Two Points
- Count Integral points inside a Triangle
- Trapezoidal Rule for Approximate Value of Definite Integral
- Program for finding the Integral of a given function using Boole's Rule
- Count of integral coordinates that lies inside a Square
- Probability that an arbitrary positive divisor of 10^X is an integral multiple of 10^Y
- Generate all integral points lying inside a rectangle
- Find integral points with minimum distance from given set of integers using BFS
- Count number of solutions of x^2 = 1 (mod p) in given range
- Number of solutions to Modular Equations
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.