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 –
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Permutations of n things taken r at a time with k things together
- Python program to find difference between current time and given time
- MoviePy – Changing Image and Time at same time of Video Clip
- 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
- Problem on permutations and combinations | Set 2
- Python - Itertools.Permutations()
- Number of palindromic permutations | Set 1
- Possible permutations at a railway track
- Print the two possible permutations from a given sequence
- All reverse permutations of an array using STL in C++
- Python | All possible permutations of N lists
- Generate all cyclic permutations of a number
- Find the number of good permutations
- Count permutations that are first decreasing then increasing.
- Generate all possible permutations of a Number divisible by N
- Count the number of special permutations
- Permutations of string such that no two vowels are adjacent
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.