Find K distinct positive odd integers with sum N | C ++ implementation to find K odd positive integers such that their sum is equal to given number ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long int NEW_LINE void findDistinctOddSum ( ll n , ll k ) { if ( ( k * k ) <= n && ( n + k ) % 2 == 0 ) { int val = 1 ; int sum = 0 ; for ( int i = 1 ; i < k ; i ++ ) { cout << val << " ▁ " ; sum += val ; val += 2 ; } cout << n - sum << endl ; } else cout << " NO ▁ STRNEWLINE " ; } int main ( ) { ll n = 100 ; ll k = 4 ; findDistinctOddSum ( n , k ) ; return 0 ; }