Represent N as sum of K odd numbers with repetitions allowed | Java implementation to represent N as sum of K even numbers ; Function to print the representation ; N must be greater than equal to 2 * K and must be odd ; Driver Code
import java . util . * ; class GFG { static void sumOddNumbers ( int N , int K ) { int check = N - ( K - 1 ) ; if ( check > 0 && check % 2 == 1 ) { for ( int i = 0 ; i < K - 1 ; i ++ ) { System . out . print ( "1 ▁ " ) ; } System . out . print ( + check ) ; } else System . out . println ( " - 1 ▁ " ) ; } public static void main ( String args [ ] ) { int N = 5 ; int K = 3 ; sumOddNumbers ( N , K ) ; } }