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:
- 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 sin(x) and cos(x)
- C program to calculate the value of nPr
- Program to calculate the value of nPr
- Program to Calculate e^x by Recursion
- Write a program to calculate pow(x,n)
- Efficient program to calculate e^x
- Program to calculate Profit Or Loss
- Program to calculate Root Mean Square
- Program to calculate GST from original and net prices
- Program to calculate Area Of Octagon
- Program to calculate distance between two points in 3 D
- Program to calculate distance between two points
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.