Find K distinct positive odd integers with sum N | Java 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
import java . util . * ; class GFG { static void findDistinctOddSum ( int n , int k ) { if ( ( k * k ) <= n && ( n + k ) % 2 == 0 ) { int val = 1 ; int sum = 0 ; for ( int i = 1 ; i < k ; i ++ ) { System . out . print ( val + " ▁ " ) ; sum += val ; val += 2 ; } System . out . print ( n - sum + "NEW_LINE"); } else System . out . print ( "NO NEW_LINE"); } public static void main ( String [ ] args ) { int n = 100 ; int k = 4 ; findDistinctOddSum ( n , k ) ; } }