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
< ? php function findIntegers ( $ n , $ x , $ y ) { $ ans = array ( ) ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) array_push ( $ ans , 1 ) ; if ( $ y - ( $ n - 1 ) <= 0 ) { echo " - 1" ; return ; } array_push ( $ ans , $ y - ( $ n - 1 ) ) ; $ store = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ store += $ ans [ $ i ] * $ ans [ $ i ] ; if ( $ store < $ x ) { echo " - 1" ; return ; } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ ans [ $ i ] , " ▁ " ; } $ n = 3 ; $ x = 254 ; $ y = 18 ; findIntegers ( $ n , $ x , $ y ) ; ? >