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
using System ; class GFG { static void oddints ( int n , int k ) { if ( n % 2 != k % 2 ) { Console . WriteLine ( " - 1" ) ; return ; } int sum = 0 ; int i = 1 ; int j = 1 ; while ( j < k ) { sum = sum + i ; Console . Write ( i + " ▁ " ) ; i = i + 2 ; j ++ ; } int finalOdd = n - sum ; Console . WriteLine ( finalOdd ) ; } public static void Main ( String [ ] args ) { int n = 10 ; int k = 2 ; oddints ( n , k ) ; } }