Split the number into N parts such that difference between the smallest and the largest part is minimum | Function that prlets the required sequence ; If we cannot split the number into exactly ' N ' parts ; If x % n == 0 then the minimum difference is 0 and all numbers are x / n ; upto n - ( x % n ) the values will be x / n after that the values will be x / n + 1 ; driver code
function split ( x , n ) { if ( x < n ) document . write ( " " ) ; else if ( x % n == 0 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( ( x / n ) + " " ) ; } else { let zp = n - ( x % n ) ; let pp = Math . floor ( x / n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i >= zp ) document . write ( ( pp + 1 ) + " " ) ; else document . write ( pp + " " ) ; } } } let x = 5 ; let n = 3 ; split ( x , n ) ;