Find any K distinct odd integers such that their sum is equal to N | C ++ implementation to find k odd integers such that their sum is 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void oddIntegers ( int n , int k ) { if ( n % 2 != k % 2 ) { cout << " - 1" << " STRNEWLINE " ; return ; } int sum = 0 ; int i = 1 ; int j = 1 ; while ( j < k ) { sum = sum + i ; cout << i << " ▁ " ; i = i + 2 ; j ++ ; } int finalOdd = n - sum ; cout << finalOdd << " STRNEWLINE " ; } int main ( ) { int n = 10 ; int k = 2 ; oddIntegers ( n , k ) ; return 0 ; }