Find K distinct positive odd integers with sum N | Function to find K odd positive integers such that their sum is N ; Condition to check if there are enough values to check ; Driver Code
function findDistinctOddSum ( n , k ) { if ( ( k * k ) <= n && ( n + k ) % 2 == 0 ) { var val = 1 ; var sum = 0 ; for ( var i = 1 ; i < k ; i ++ ) { document . write ( val + " " ) ; sum += val ; val += 2 ; } document . write ( n - sum ) ; } else document . write ( " " ) ; } var n = 100 ; var k = 4 ; findDistinctOddSum ( n , k ) ;