Given three numbers b, x, n. The task is to find the values of ‘a’ in equation (a+b) <= n such that a+b is divisible by x. If no such values are possible then print -1.
Input: b = 10, x = 6, n = 40 Output: 2 8 14 20 26 Input: b = 10, x = 1, n = 10 Output: -1
Approach: One can find the least possible value (b/x + 1)*x – b. Then we increase answer by x until it is not greater than n. Here (b/x + 1)*x is the least possible value which is divisible by x.
Below is the implementation of above approach:
2 8 14 20 26
- Number of sextuplets (or six values) that satisfy an equation
- Print k numbers where all pairs are divisible by m
- Print digit's position to be removed to make a number divisible by 6
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
- Find permutation of n which is divisible by 3 but not divisible by 6
- Find the missing value from the given equation a + b = c
- Number of solutions for the equation x + y + z <= n
- Sort an array after applying the given equation
- Equation of circle from centre and radius
- Find the number of solutions to the given equation
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- Solve the Linear Equation of Single Variable
- Equation of ellipse from its focus, directrix, and eccentricity
- Program to find the Roots of Quadratic equation
- Number of non-negative integral solutions of sum equation
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.