Given two positive integers n and r where n > r >1. The task is to find the value of f(n)/(f(r)*f(n-r)). F(n) is deined as follows:
1-1 *2-2 *3-3 *….. n-n
Input: n = 5, r = 3 Output: 1/200000 Input: n = 3, r = 2 Output: 1/27
A naive approach to solve this question is to calculate f(n), f(r) and f(n-r) separately and then calculating the result as per given formula but that will cost a bit high of time complexity.
A better approach to solve this question is to find the greater value among r and n-r and then after using the property f(n) = f(n-1)* n-n = f(n-1)/nn of given function, eliminate the greater among f(r) and f(n-r) from numerator and denominator. After that calculate the rest of value by using simple loop and power function.
find max(r, n-r).
iterate from max(r, n-r) to n
result = ((result * i-i / (i-max(r, n-r)) -(i-max(r, n-r)) )
Below is the implementation of the above approach:
- Find K such that |A - K| = |B - K|
- Find the value of max(f(x)) - min(f(x)) for a given F(x)
- Find N from the value of N!
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find (1^n + 2^n + 3^n + 4^n) mod 5 | Set 2
- Find 2^(2^A) % B
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find x and y satisfying ax + by = n
- Find larger of x^y and y^x
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Find the value of ln(N!) using Recursion
- Find minimum x such that (x % k) * (x / k) == n | Set-2
- Find minimum x such that (x % k) * (x / k) == n
- Find N values of X1, X2, ... Xn such that X1 < X2 < ... < XN and sin(X1) < sin(X2) < ... < sin(XN)
- Find (a^b)%m where 'a' is very large
- Find all divisors of N2 using N
- Find maximum value of x such that n! % (k^x) = 0
- Find the sum of all multiples of 2 and 5 below N
- Find the value of N when F(N) = f(a)+f(b) where a+b is the minimum possible and a*b = N
- Find two numbers from their sum and XOR
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.