Given three integers N, X and Y. The task is to find N positive integers that satisfy the given equations.
- a12 + a22 + …. + an2 ≥ X
- a1 + a2 + …. + an ≤ Y
If no such sequence of integers is possible then print -1.
Input: N = 3, X = 254, Y = 18
Output: 1 1 16
12 + 12 + 162 = 1 + 1 + 256 = 258 which is ≥ X
1 + 1 + 16 = 18 which is ≤ Y
Input: N = 2, X = 3, Y = 2
No such sequence exists.
Approach: It is easy to see that in order to maximize the sum of squares, one should make all numbers except the first one equal to 1 and maximize the first number. Keeping this in mind we only need to check whether the given value of y is large enough to satisfy a restriction that all n numbers are positive. If y is not too small, then all we need is to ensure that X ≤ 1 + 1 + … + (y – (n – 1))2.
Below is the implementation of the above approach:
1 1 16
- Pair of integers (a, b) which satisfy the given equations
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Ways to write N as sum of two or more positive integers | Set-2
- Check whether product of integers from a to b is positive , negative or zero
- Number of ways in which N can be represented as the sum of two positive integers
- Represent (2 / N) as the sum of three distinct positive integers of the form (1 / m)
- Maximum number of distinct positive integers that can be used to represent N
- Count positive integers with 0 as a digit and maximum 'd' digits
- Check whether a number can be represented as sum of K distinct positive integers
- Number of arrays of size N whose elements are positive integers and sum is K
- Find the values of X and Y in the Given Equations
- Find n-variables from n sum equations with one missing
- Find the repeating and the missing number using two equations
- Find 'N' number of solutions with the given inequality 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 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.