Find n positive integers that satisfy the given equations | C # implementation of the approach ; Function to find n positive integers that satisfy the given conditions ; To store n positive integers ; Place N - 1 one 's ; If can not place ( y - ( n - 1 ) ) as the Nth integer ; Place Nth integer ; To store the sum of squares of N integers ; If it is less than x ; Print the required integers ; Driver code
using System ; using System . Collections ; class GFG { static void findIntegers ( int n , int x , int y ) { ArrayList ans = new ArrayList ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) ans . Add ( 1 ) ; if ( y - ( n - 1 ) <= 0 ) { Console . Write ( " - 1" ) ; return ; } ans . Add ( y - ( n - 1 ) ) ; int store = 0 ; for ( int i = 0 ; i < n ; i ++ ) store += ( int ) ans [ i ] * ( int ) ans [ i ] ; if ( store < x ) { Console . Write ( " - 1" ) ; return ; } for ( int i = 0 ; i < n ; i ++ ) Console . Write ( ( int ) ans [ i ] + " ▁ " ) ; } static void Main ( ) { int n = 3 , x = 254 , y = 18 ; findIntegers ( n , x , y ) ; } }