Marbles question doubt


wrong answer is coming, i have used (n-1)C(k-1).can you explain a short reason for this formula. and why can’t we use k^(n-k) insteed?

See, if we choose n balls, then k balls have to be of k different colours for sure.

We now have to select n-k balls with k types of options.
There is a general formula for this case (Using PnC) :
(n+r−1)! / (n−1)!⋅r!

Put the new value (n-k) instead of n in the mathematical formula to get the New formula for our question that equals to C(n-1,k-1).
I hope i am clear and you shall be able to implement the code :slight_smile:

I would like to tell you that answer wont fit in 64 bit integer in this problem… so use string multiplication or python or submit your sol on spoj because on spoj answer will fit in 64 bit integer…