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.
- Number of integral solutions for equation x = b*(sumofdigits(x)^a)+c
- Number of non-negative integral solutions of sum equation
- 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
- Number of solutions for x < y, where a <= x <= b and c <= y <= d and x, y are integers
- Number of solutions of n = x + n ⊕ x
- Number of solutions to Modular Equations
- Count number of solutions of x^2 = 1 (mod p) in given range
- 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
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.