Comment

avatar username

Your strategy of computing binomial coefficients is incorrect.

Why it is incorrect

Suppose we're trying to compute ${{15}\choose{9}}$, which is $\dfrac{10 \cdot 11 \cdot 12 \cdot 13 \cdot 14 \cdot 15}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6}$. In your implementation, you will first pick a number from the numerator which is divisible by $6$, and divide it by $6$. You will get $\dfrac{10 \cdot 11 \cdot 2 \cdot 13 \cdot 14 \cdot 15}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5}$, and you can't get rid of $4$ in the denominator since no multiple in the numerator is divisible by $4$.

How to fix it

Option 1: Pascal's triangle.

Option 2: factorials and inverse factorials.

Option 3: factorize all multiples in the denominator, so instead of working with $1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6$, you work with $1 \cdot 2 \cdot 3 \cdot 2 \cdot 2 \cdot 5 \cdot 2 \cdot 3$, and the issue does not arise.

The actual rating of this user is 2643.

Original comment.

Statistics