# Total number of days taken to complete the task if after certain days one person leaves

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.

**Examples:**

Input:a = 10, b = 20, n = 5

Output:10

Input:a = 5, b = 15, n = 3

Output:6

**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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the ` `// number of days required ` `int` `numberOfDays(` `int` `a, ` `int` `b, ` `int` `n) ` `{ ` ` ` `int` `Days = b * (n + a) / (a + b); ` ` ` ` ` `return` `Days; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a = 10, b = 20, n = 5; ` ` ` ` ` `cout << numberOfDays(a, b, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the ` `// number of days required ` `static` `int` `numberOfDays(` `int` `a, ` `int` `b, ` `int` `n) ` `{ ` ` ` `int` `Days = b * (n + a) / (a + b); ` ` ` ` ` `return` `Days; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` ` ` `int` `a = ` `10` `, b = ` `20` `, n = ` `5` `; ` ` ` `System.out.println (numberOfDays(a, b, n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by jit_t ` |

*chevron_right*

*filter_none*

## Python3

`# Python implementation of the approach ` ` ` `# Function to return the ` `# number of days required ` `def` `numberOfDays(a, b, n) : ` ` ` ` ` `Days ` `=` `b ` `*` `(n ` `+` `a) ` `/` `/` `(a ` `+` `b) ` ` ` ` ` `return` `Days ` ` ` `# Driver code ` ` ` `a ` `=` `10` `b ` `=` `20` `n ` `=` `5` ` ` `print` `(numberOfDays(a, b, n)) ` ` ` `# This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the ` ` ` `// number of days required ` ` ` `static` `int` `numberOfDays(` `int` `a, ` `int` `b, ` `int` `n) ` ` ` `{ ` ` ` `int` `Days = b * (n + a) / (a + b); ` ` ` ` ` `return` `Days; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` ` ` `int` `a = 10, b = 20, n = 5; ` ` ` `Console.WriteLine(numberOfDays(a, b, n)); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

**Output:**

10

## Recommended Posts:

- Find number of days between two given dates
- Program to calculate the number of odd days in given number of years
- Date after adding given number of days to the given date
- Program to find total number of edges in a Complete Graph
- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Number of different positions where a person can stand
- Largest number by which given 3 numbers should be divided such that they leaves same remainder
- Maximum number of 3-person teams formed from two groups
- Find the total number of composite factor for a given number
- Find the total Number of Digits in (N!)N
- Count total number of digits from 1 to n
- Count total number of even sum sequences
- Total number of divisors for a given number
- Total number of different staircase that can made from N boxes
- Total number of non-decreasing numbers with n digits

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.