-1
\$\begingroup\$

This question already has an answer here:

The problem is to compute nCr = n!/(r!) * (n-r)! in the fewest characters possible. The input will be in the form: 1st line will have number of test cases and second line will have n and r for each testcase. You need to print ncr

e.g.

Input
1
100 10

Output:
17310309456440

Here's what I have in python. Is there a way to reduce the number of characters further ?[143 chars presently]

r=raw_input
f=lambda x:0**x or x*f(x-1)
C=lambda n,r:f(n)/f(r)/f(n-r)
for i in range(int(r())):print C(*map(int, r().split()))

Thanks!

\$\endgroup\$

marked as duplicate by cardboard_box, grc, John Dvorak, SeanC, Howard Nov 18 '13 at 21:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    \$\begingroup\$ from sympy import binomial \$\endgroup\$ – alephalpha Nov 18 '13 at 5:42
0
\$\begingroup\$

Python 3 (100 chars)

I=input
C=lambda n,r:r and C(n-1,r-1)*n//r or 1
for _ in' '*int(I()):print(C(*map(int,I().split())))
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.