Given n and m, the task is to find the number of permutations of n distinct things taking them all at a time such that m particular things never come together.
Input : 7, 3 Output : 420 Input : 9, 2 Output : 282240
Derivation of the formula –
Total number of arrangements possible using n distinct objects taking all at a time =
Number of arrangements of n distinct things taking all at a time, when m particular things always come together, is
Hence, the number of permutations of distinct things taking all at a time, when particular things never come together –
Permutations = n! - (n-m+1)! × m!
Below is the Python implementation of above approach –
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
- Permutations of n things taken r at a time with k things together
- Python program to find difference between current time and given time
- Time Functions in Python | Set 1 (time(), ctime(), sleep()...)
- Minimum time to reach a point with +t and -t moves at time t
- All permutations of an array using STL in C++
- Python | time.time() method
- Print the two possible permutations from a given sequence
- Python | All possible permutations of N lists
- All reverse permutations of an array using STL in C++
- Python - Itertools.Permutations()
- Problem on permutations and combinations | Set 2
- Number of palindromic permutations | Set 1
- Count the number of special permutations
- Permutations of string such that no two vowels are adjacent
- Count of possible permutations of a number represented as a sum of 2's, 4's and 6's only
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.