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 the number of positive integers less than or equal to N that have an odd number of digits
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Find K distinct positive odd integers with sum N
- Find 'N' number of solutions with the given inequality equations
- Find the values of X and Y in the Given Equations
- Find if two given Quadratic equations have common roots or not
- Find numbers a and b that satisfy the given conditions
- Find the Number of Permutations that satisfy the given condition in an array
- Count 'd' digit positive integers with 0 as a digit
- Count positive integers with 0 as a digit and maximum 'd' digits
- Number of arrays of size N whose elements are positive integers and sum is K
- 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
- Check whether a number can be represented as sum of K distinct positive integers
- Number of ways in which N can be represented as the sum of two positive integers
- Maximum number of distinct positive integers that can be used to represent N
- Represent (2 / N) as the sum of three distinct positive integers of the form (1 / m)
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
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.