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
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Minimum steps to come back to starting point in a circular tour
- In how many ways the ball will come back to the first boy after N turns
- Time taken by two persons to meet on a circular track
- Time taken per hour for stoppage of Car
- Python - Measure time taken by program to execute
- Minimum time required to complete a work by N persons together
- Number of ways to arrange a word such that all vowels occur together
- Count numbers have all 1s together in binary representation
- Total number of days taken to complete the task if after certain days one person leaves
- Find if the Vacation can be taken or not
- Minimum moves taken to move coin of each cell to any one cell of Matrix
- Print anagrams together in Python using List and Dictionary
- Total number of ways to place X and Y at n places such that no two X are together
- Python | Check if given words appear together in a list of sentence
- Number of ways to arrange a word such that no vowels occur together
- Seating arrangement of N boys sitting around a round table such that two particular boys sit together
- Probability of not getting two consecutive heads together in N tosses of coin
- Distance Traveled by Two Trains together in the same Direction
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.