Given that person A takes a days to do a certain piece of work while person B takes b days to do the same work. If A and B started the work together and n days before the completion of work, A leaves the work. Find the total number of days taken to complete work.
Input: a = 10, b = 20, n = 5
Input: a = 5, b = 15, n = 3
Approach: Let D be the total number of days to complete the work. A and B work together for D – n days. So,
(D – n) * (1/a + 1/b) + (n) * (1/b) = 1
D * (1/a + 1/b) – (n/a) – (n/b) + (n/b) = 1
D * (1/a + 1/b) = (n + a) / a
D = b * (n + a) / (a + b)
Below is the implementation of the 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.
- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Minimum time required to complete exactly K tasks based on given order of task execution
- Number of array elements derivable from D after performing certain operations
- Minimum moves taken to move coin of each cell to any one cell of Matrix
- Count of ways to distribute N items among 3 people with one person receiving maximum
- Program to find total number of edges in a Complete Graph
- Biggest number by arranging numbers in certain order
- Total ways of choosing X men and Y women from a total of M men and W women
- Date after adding given number of days to the given date
- Find the day of the week after K days from the given day
- Largest number by which given 3 numbers should be divided such that they leaves same remainder
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Mimimum number of leaves required to be removed from a Tree to satisfy the given condition
- Maximum number of 3-person teams formed from two groups
- Number of different positions where a person can stand
- Permutations of n things taken r at a time with k things together
- Time taken by two persons to meet on a circular track
- Time taken per hour for stoppage of Car
- Permutations of n things taken all at a time with m things never come together
- Find if the Vacation can be taken or not
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.