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 –
- Permutations of n things taken r at a time with k things together
- Minimum time to reach a point with +t and -t moves at time t
- Time Functions in Python | Set 1 (time(), ctime(), sleep()...)
- Python | time.time() method
- All permutations of an array using STL in C++
- Number of palindromic permutations | Set 1
- All reverse permutations of an array using STL in C++
- Python | All possible permutations of N lists
- Problem on permutations and combinations | Set 2
- Print all permutations of a string in Java
- Count permutations that are first decreasing then increasing.
- Check if two Linked Lists are permutations of each other
- Find the number of good permutations
- Permutations of string such that no two vowels are adjacent
- Generate all cyclic permutations of a number
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.