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
- All possible values of floor(N/K) for all values of K
- Find permutation of n which is divisible by 3 but not 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]
- Absolute difference between sum and product of roots of a quartic equation
- Equation of circle from centre and radius
- Equation of ellipse from its focus, directrix, and eccentricity
- Satisfy the parabola when point (A, B) and the equation is given
- Sum of minimum value of x and y satisfying the equation ax + by = c
- Find the equation of plane which passes through two points and parallel to a given axis
- Find number of solutions of a linear equation of n variables
- Runge-Kutta 4th Order Method to Solve Differential Equation
- Sort an array after applying the given equation
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Euler Method for solving differential equation
- Number of non-negative integral solutions of sum equation
- Solve the Linear Equation of Single Variable
- Number of integral solutions for equation x = b*(sumofdigits(x)^a)+c
- Program to find number of solutions in Quadratic 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 firstname.lastname@example.org. 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.