Split a number as sum of K numbers which are not divisible by K | C ++ program to split a number as sum of K numbers which are not divisible by K ; Function to split into K parts and print them ; Print 1 K - 1 times ; Print N - K + 1 ; Print 1 K - 2 times ; Print 2 and N - K ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printKParts ( int N , int K ) { if ( N % K == 0 ) { for ( int i = 1 ; i < K ; i ++ ) cout << "1 , ▁ " ; cout << N - ( K - 1 ) << endl ; } else { if ( K == 2 ) { cout << " Not ▁ Possible " << endl ; return ; } for ( int i = 1 ; i < K - 1 ; i ++ ) cout << 1 << " , ▁ " ; cout << 2 << " , ▁ " << N - K << endl ; } } int main ( ) { int N = 18 , K = 5 ; printKParts ( N , K ) ; return 0 ; }