We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Mathematics
- Combinatorics
- nCr table
- Discussions
nCr table
nCr table
Sort by
recency
|
117 Discussions
|
Please Login in order to post a comment
Python
math.comb
is so fast that the following brute-force one-liner works:You can watch Raymond Hettinger's amazing talk "Numerical Marvels Inside Python" to understand why
math.comb
is so fast, including with very very largen
(group theory ahead!).def solve(n): ncr = [] for r in range (n//2 + 1): ncr.append(comb(n, r)%(10**9)) if n % 2== 0: return ncr + ncr[:-1][::-1] else: return ncr + ncr[::-1]
My accepted Go solution:
My accepted C# solution:
1 line Python solution, 100%
You might need to overwrite the default recursion limit, also can use memoization for extra speed (so multiple testcases in the same run are faster, reusing already generated rows of Pascal's triangle)