# Find ‘N’ number of solutions with the given inequality equations

Find the value of **a _{1}, a_{2}, a_{3}, ….a_{n}** such that the following two conditions are satisfied.

Print the value of

**a**and “No solution” otherwise.

_{1}, a_{2}, …, a_{n}**Note:**There maybe a several solutions, print any of them .

**Examples:**

Input:n = 5, x = 15, y = 15Output:11 1 1 1 1Input:n = 4, x = 324, y = 77Output:74 1 1 1

**Approach:** Below is the step by step algorithm to solve this problem:

- Initialize the number of elements and the value of x and y.
- There is no solution of a
_{1}…a_{2}if y is less than n or if x is very larger than n. - Print first solution as y – n + 1 and 1 as the solution of rest of the elements.

Below is the implementation of above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` `#define ll long long ` ` ` `// Function to calculate all the solutions ` `void` `findsolution(ll n, ll x, ll y) ` `{ ` ` ` `// there is no solutions ` ` ` `if` `((y - n + 1) * (y - n + 1) + n - 1 < x || y < n) { ` ` ` `cout << ` `"No solution"` `; ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// print first element as y-n+1 ` ` ` `cout << y - n + 1; ` ` ` ` ` `// print rest n-1 elements as 1 ` ` ` `while` `(n-- > 1) ` ` ` `cout << endl ` ` ` `<< 1; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// initialize the number of elements ` ` ` `// and the value of x an y ` ` ` `ll n, x, y; ` ` ` `n = 5, x = 15, y = 15; ` ` ` ` ` `findsolution(n, x, y); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// java implementation of above approach ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` `// Function to calculate all the solutions ` `static` `void` `findsolution(` `long` `n, ` `long` `x, ` `long` `y) ` `{ ` ` ` `// there is no solutions ` ` ` `if` `((y - n + ` `1` `) * (y - n + ` `1` `) + n - ` `1` `< x || y < n) { ` ` ` `System.out.println( ` `"No solution"` `); ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// print first element as y-n+1 ` ` ` `System.out.println( y - n + ` `1` `); ` ` ` ` ` `// print rest n-1 elements as 1 ` ` ` `while` `(n-- > ` `1` `) ` ` ` `System.out.println( ` `"1"` `); ` `} ` ` ` `// Driver code ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `// initialize the number of elements ` ` ` `// and the value of x an y ` ` ` `long` `n, x, y; ` ` ` `n = ` `5` `; x = ` `15` `; y = ` `15` `; ` ` ` ` ` `findsolution(n, x, y); ` ` ` `} ` `} ` `// This code is contributed ` `// by ajit ` |

*chevron_right*

*filter_none*

## Python3

# Python3 implementation of above approach

# Function to calculate all the solutions

def findsolution(n, x, y):

# there is no solutions

if ((y – n + 1) * (y – n + 1) +

n – 1 < x or y < n):
print("No solution");
return;
# print first element as y-n+1
print(y - n + 1);
# print rest n-1 elements as 1
while (n > 1):

print(1);

n -= 1;

# Driver code

# initialize the number of elements

# and the value of x an y

n = 5;

x = 15;

y = 15;

findsolution(n, x, y);

# This code is contributed by mits

## C#

`// C# implementation of above approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to calculate all the solutions ` `static` `void` `findsolution(` `long` `n, ` ` ` `long` `x, ` `long` `y) ` `{ ` ` ` `// there is no solutions ` ` ` `if` `((y - n + 1) * (y - n + 1) + ` ` ` `n - 1 < x || y < n) ` ` ` `{ ` ` ` `Console.WriteLine( ` `"No solution"` `); ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// print first element as y-n+1 ` ` ` `Console.WriteLine( y - n + 1); ` ` ` ` ` `// print rest n-1 elements as 1 ` ` ` `while` `(n-- > 1) ` ` ` `Console.WriteLine( ` `"1"` `); ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `// initialize the number of elements ` ` ` `// and the value of x an y ` ` ` `long` `n, x, y; ` ` ` `n = 5; x = 15; y = 15; ` ` ` ` ` `findsolution(n, x, y); ` `} ` `} ` ` ` `// This code is contributed ` `// by ajit ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function to calculate all the solutions ` `function` `findsolution(` `$n` `, ` `$x` `, ` `$y` `) ` `{ ` ` ` `// there is no solutions ` ` ` `if` `((` `$y` `- ` `$n` `+ 1) * (` `$y` `- ` `$n` `+ 1) + ` ` ` `$n` `- 1 < ` `$x` `|| ` `$y` `< ` `$n` `) ` ` ` `{ ` ` ` `echo` `"No solution"` `; ` ` ` `return` `; ` ` ` `} ` ` ` ` ` `// print first element as y-n+1 ` ` ` `echo` `$y` `- ` `$n` `+ 1; ` ` ` ` ` `// print rest n-1 elements as 1 ` ` ` `while` `(` `$n` `-- > 1) ` ` ` `echo` `"\n"` `. 1; ` `} ` ` ` `// Driver code ` ` ` `// initialize the number of elements ` `// and the value of x an y ` `$n` `= 5; ` `$x` `= 15; ` `$y` `= 15; ` ` ` `findsolution(` `$n` `, ` `$x` `, ` `$y` `); ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

**Output:**

11 1 1 1 1

## Recommended Posts:

- Number of solutions to Modular Equations
- Find the repeating and the missing number using two equations
- Find the number of solutions to the given equation
- Find number of solutions of a linear equation of n variables
- Program to find number of solutions in Quadratic Equation
- Find the values of X and Y in the Given Equations
- Find n-variables from n sum equations with one missing
- Find n positive integers that satisfy the given equations
- Program to find root of an equations using secant method
- Number of solutions for the equation x + y + z <= n
- 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
- Number of non-negative integral solutions of a + b + c = n
- Count number of solutions of x^2 = 1 (mod p) in given range
- Number of integral solutions of the equation x1 + x2 +.... + xN = k

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.