I am working on a problem on codeforce. I came up with a method but it solves down to a formula which is

\frac{n!}{w!r!}, ! stands for factorials of number.

How can I work such problems out?

I am working on a problem on codeforce. I came up with a method but it solves down to a formula which is

\frac{n!}{w!r!}, ! stands for factorials of number.

How can I work such problems out?

How to work means ? What u wanna ask ? Share the problem link for more helpâ€¦

Itâ€™s not a specific problem. It is just like I want to calculate the formula, knowing that it will reduce to some simple natural number.

Like \frac{10!}{6!2!}

In any of problem if situation comes to compute the value of nCr then the contraints are set such that we can iterate over the smaller of the two factorials in denominator and compute the answer. And if we are required to calculate the value for large constraints then we must have given some modulo number and in that case we can compute the factorial of all the number and then take inverse modulo for the denominator (if the given modulo number is prime. In case it is not then we have to do a little bit of extra work.)

For code you can refer this : https://cp-algorithms.com/combinatorics/binomial-coefficients.html

inverse modulus : https://www.quora.com/How-do-I-find-the-value-of-nCr-1000000007-for-the-large-number-n-n-10-6-in-C

1 Like

U can also go with method stated by @pk301

But some problems may require fast calculations and calculating mod inverse may be slow and It can also give wa in some cases when denominator doesnâ€™t satisfy conditions for the method used for mod inverse and also some numbers mod inverse does not existâ€¦

Hence, While calculating nCr if in n*r fits an 2D arrayâ€¦ and U need to use nCr it more often in your solution then u can make a pascalâ€™s triangle which will take O(n^2) time complexityâ€¦

1 Like

but u r working on a problem of CF rightâ€¦ so I was asking for that question linkâ€¦