-1
$\begingroup$

You are given two integers $N$ and $K$. Find all ways to represent $N$ as the sum of exactly $K$ distinct positive integers $x_1,x_2, \ldots,x_K$ — in other words.

$xi_>0$ for each valid $i$;

$x_i \neq x_j$ for each valid $i \neq j$;

$x_1+x_2+ \ldots +x_K=N$

For Example : $N=15$ and $K=3$

Answer should be: $1+2+12, 1+3+11, 1+4+10, 1+5+9, 1+6+8, 2+3+10, 2+4+9, 2+5+8, 2+6+7, 3+4+8, 3+5+7, 4+5+6$

How to code to generate these combinations in any language?

$\endgroup$
3

1 Answer 1

3
$\begingroup$

Are you currently participating in SnackDown Round 1B, Then you should not ask this question before the competition ends, you are violating the codechef code of conduct for the competition.

$\endgroup$
2
  • $\begingroup$ If this problem is drawn from an open contest, then you should vote to close it on those grounds. Hit flag at the bottom of the question, select in need of moderator intervention, and then explain that this is an open contest question in the dialog box, which will alert the moderators that this question is drawn from an open contest, which is a violation of site rules. $\endgroup$ Commented Oct 29, 2018 at 11:39
  • $\begingroup$ Now the Contest was ended. Please give answer to my question. $\endgroup$ Commented Oct 30, 2018 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .