Find n positive integers that satisfy the given equations | 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
function findIntegers ( n , x , y ) { let ans = [ ] ; for ( let i = 0 ; i < n - 1 ; i ++ ) ans . push ( 1 ) ; if ( y - ( n - 1 ) <= 0 ) { document . write ( " " ) ; return ; } ans . push ( y - ( n - 1 ) ) ; let store = 0 ; for ( let i = 0 ; i < n ; i ++ ) store += ans [ i ] * ans [ i ] ; if ( store < x ) { document . write ( " " ) ; return ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( ans [ ( i ) ] + " " ) ; } let n = 3 , x = 254 , y = 18 ; findIntegers ( n , x , y ) ;