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
- Ways to write N as sum of two or more positive integers | Set-2
- Number of ways in which N can be represented as the sum of two positive integers
- Check whether product of integers from a to b is positive , negative or zero
- Number of arrays of size N whose elements are positive integers and sum is K
- 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
- Maximum number of distinct positive integers that can be used to represent N
- Find the values of X and Y in the Given Equations
- Find n-variables from n sum equations with one missing
- Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z
- Find the repeating and the missing number using two equations
- Find 'N' number of solutions with the given inequality equations
- Program to find root of an equations using secant method
- Find numbers a and b that satisfy the given conditions
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
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.