Find any K distinct odd integers such that their sum is equal to N | Function to find K odd integers such that their sum is N ; Condition to check if there exist such K integers ; Loop to find first K - 1 distinct odd integers ; Final Kth odd number ; Driver code
function oddIntegers ( n , k ) { if ( n % 2 != k % 2 ) { document . write ( " " ) ; return ; } var sum = 0 ; var i = 1 ; var j = 1 ; while ( j < k ) { sum = sum + i ; document . write ( i + " " ) ; i = i + 2 ; j ++ ; } var finalOdd = n - sum ; document . write ( finalOdd ) ; } var n = 10 ; var k = 2 ; oddIntegers ( n , k ) ;