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
- Python program to find difference between current time and given time
- 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++
- Problem on permutations and combinations | Set 2
- Number of palindromic permutations | Set 1
- All reverse permutations of an array using STL in C++
- Python | All possible permutations of N lists
- Permutations of string such that no two vowels are adjacent
- Count the number of special permutations
- Print all permutations of a string in Java
- Check if two Linked Lists are permutations of each other
- Find the number of good permutations
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.