# Program to find the number of men initially

A certain number of men can do a certain piece of work in D days. If there were m more men engaged in the work then the work can be done in d days less. The task is to find how many men were there initially.

Examples:

Input: D = 5, m = 4, d = 4
Output: 1

Input: D = 180, m = 30, d = 20
Output: 240

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: Let the initial number of men be M and days be D
Amount of work completed M men in D days will be M * D
i.e. Work Done = M * D …(1)
If there are M + m men then the same amount of work is completed in D – d days.
i.e. Work Done = (M + m) * (D – d) …(2)
Equating equations 1 and 2,

M * D = (M + m) * (D – d)
M * D = M * (D – d) + m * (D – d)
M * D – M * (D – d) = m * (D – d)
M * (D – (D – d)) = m * (D – d)
M = m * (D – d) / d

Below is the implementation of the above approach:

## C++

 `// C++ implementation of above approach. ` `#include ` `using` `namespace` `std; ` ` `  `// Function to return the ` `// number of men initially ` `int` `numberOfMen(``int` `D, ``int` `m, ``int` `d) ` `{ ` ` `  `    ``int` `Men = (m * (D - d)) / d; ` ` `  `    ``return` `Men; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `D = 5, m = 4, d = 4; ` ` `  `    ``cout << numberOfMen(D, m, d); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of the approach  ` `import` `java.util.*; ` ` `  `class` `GFG  ` `{  ` `     `  `// Function to return the  ` `// number of men initially  ` `static` `int` `numberOfMen(``int` `D, ``int` `m, ``int` `d)  ` `{  ` ` `  `    ``int` `Men = (m * (D - d)) / d;  ` ` `  `    ``return` `Men;  ` `}  ` ` `  `// Driver code  ` `public` `static` `void` `main(String args[]) ` `{  ` `    ``int` `D = ``5``, m = ``4``, d = ``4``;  ` ` `  `    ``System.out.println(numberOfMen(D, m, d));  ` ` `  `}  ` `}  ` `// This code is contributed by Arnab Kundu `

## Python3

 `# Python implementation of above approach.  ` ` `  `# Function to return the  ` `# number of men initially  ` `def` `numberOfMen(D, m, d): ` `    ``Men ``=` `(m ``*` `(D ``-` `d)) ``/` `d;  ` ` `  `    ``return` `int``(Men);  ` ` `  ` `  `# Driver code  ` `D ``=` `5``; m ``=` `4``; d ``=` `4``;  ` ` `  `print``(numberOfMen(D, m, d));  ` ` `  ` `  `# This code contributed by Rajput-Ji `

## C#

 `//  C# implementation of the approach  ` `using` `System; ` ` `  `class` `GFG  ` `{  ` `     `  `// Function to return the  ` `// number of men initially  ` `static` `int` `numberOfMen(``int` `D, ``int` `m, ``int` `d)  ` `{  ` ` `  `    ``int` `Men = (m * (D - d)) / d;  ` ` `  `    ``return` `Men;  ` `}  ` ` `  `// Driver code  ` `public` `static` `void` `Main() ` `{  ` `    ``int` `D = 5, m = 4, d = 4;  ` ` `  `    ``Console.WriteLine(numberOfMen(D, m, d));  ` ` `  `}  ` `}  ` ` `  `// This code is contributed by anuj_67.. `

Output:

```1
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Improved By : andrew1234, vt_m, Rajput-Ji

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.