Given a, b and c which are part of the equation x = b * ( sumdigits(x) ^ a ) + c.
Where sumdigits(x) determines the sum of all digits of the number x. The task is to find out all integer solutions for x that satisfy the equation and print them in increasing order.
Given that, 1<=x<=109
Input: a = 3, b = 2, c = 8
Output: 10 2008 13726
Values of x are: 10 2008 13726. For 10, s(x) is 1; Putting value of s(x) in equation b*(s(x)^a)+c we get 10, and as 10 lies in range 0<x<1e+9, therefore 10 is a possible answer, similar for 2008 and 13726. No other value of x satisfies the equation for the given value of a, b and c
Input: a = 2, b = 2, c = -1
Output: 1 31 337 967
Values of x that satisfy the equation are: 1 31 337 967
Approach: sumdigits(x) can be in the range of 1<=s(X)<=81 for the given range of x i.e 0<x<1e+9. This is because value of x can be minimum 0 where sumdigits(x)=0 and maximum 999999999 where sumdigits(x) is 81. So first iterate through 1 to 81 to find x from the given equation, then cross check if the sum of digits of the number found, is same as the value of sum sumdigits(x). If both are same then increase the counter and store the result in an array.
Below is the implementation of the above approach:
1 31 337 967
Time Complexity: O(N)
Auxiliary Space: O(N)
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- 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
- 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
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.