Given two numbers n, r ( n>=r ). The task is to find the value of C(n, r) for big value of n.
Input: n = 30, r = 15 Output: 155117520 C(30, 15) is 155117520 by 30!/((30-15)!*15!) Input: n = 50, r = 25 Output: 126410606437752
Approach: A simple code can be created with the following knowledge that :
C(n, r) = [n * (n-1) * .... * (n-r+1)] / [r * (r-1) * .... * 1]
However, for big values of n, r the products may overflow, hence during each iteration we divide the current variables holding value of products by their gcd.
Below is the required implementation:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- C Program for efficiently print all prime factors of a given number
- Java Program for efficiently print all prime factors of a given number
- Program to calculate value of nCr
- Program to calculate the value of nPr
- C program to calculate the value of nPr
- Write a program to calculate pow(x,n)
- Program to calculate the value of sin(x) and cos(x) using Expansion
- Efficient program to calculate e^x
- Program to Calculate e^x by Recursion
- Program to calculate GST from original and net prices
- Program to calculate Area Of Octagon
- Program to calculate Root Mean Square
- Program to calculate Electricity Bill
- Program to calculate Profit Or Loss
- Program to calculate the area of Kite
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.