Given three integers N, R and P where P is prime, the task is to find whether NCR is divisible by P or not.
Input: N = 6, R = 2, P = 7
6C2 = 15 which is not divisible by 7.
Input: N = 7, R = 2, P = 3
7C2 = 21 which is divisible by 3.
Approach: We know that NCR = N! / (R! * (N – R)!). Now using Legendre Formula, find the largest power of P which divides any N!, R! and (N -R)! say x1, x2 and x3 respectively.
In order for NCR to be divisible by P, the condition x1 > x2 + x3 must be satisfied.
Below is the implementation of the above approach:
- Check if the sum of primes is divisible by any prime from the array
- Quick ways to check for Prime and find next Prime in Java
- Check if LCM of array elements is divisible by a prime number or not
- Sum of largest divisible powers of p (a prime number) in a range
- Find coordinates of a prime number in a Prime Spiral
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Find permutation of n which is divisible by 3 but not divisible by 6
- Check if a number is divisible by all prime divisors of another number
- Find the Nth term divisible by a or b or c
- Find nth number that contains the digit k or divisible by k.
- Find the number closest to n and divisible by m
- Find N digits number which is divisible by D
- Find Nth smallest number that is divisible by 100 exactly K times
- Find a subarray whose sum is divisible by size of the array
- Find the maximum number of elements divisible by 3
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.