# Area of plot remaining at the end

Given two integers **N** and **M** that represent the length and breadth of a rectangular plot and another integer **K** that represent the number of persons. Each person will divide the plot into two parts such that it will be the largest possible square from the plot and will leave the second part for others, it continues until the plot is over or every person gets the plot. Now, The task is to determine the area of the plot left in the end.

**Examples:**

Input:N = 5, M = 3, K = 2

Output:2

1st person divides the 5×3 plot into 2 parts i.e 3×3 and 2×3

and will get the plot having dimension 3×3. The other person divides the 2×3 plot again into

two parts i.e 2×2 and 1×2 and will get the plot having dimension 2×2. Now, the remaining

part of plot is having dimension 1×2 and area as 2 units.

Input:N = 4, M = 8, K = 4

Output:0

**Approach:**

- If Length is greater than breadth then subtract breadth from length.
- If breadth is greater than length then subtract length from breadth.
- Repeat the above steps for all the persons while there area of the reamaining plot is greater than 0.
- Print the area of the remaining plot in the end i.e. length * breadth.

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 area ` `// of the remaining plot ` `int` `remainingArea(` `int` `N, ` `int` `M, ` `int` `K) ` `{ ` ` ` ` ` `// Continue while plot has positive area ` ` ` `// and there are persons left ` ` ` `while` `(K-- && N && M) { ` ` ` ` ` `// If length > breadth ` ` ` `// then subtract breadth from length ` ` ` `if` `(N > M) ` ` ` `N = N - M; ` ` ` ` ` `// Else subtract length from breadth ` ` ` `else` ` ` `M = M - N; ` ` ` `} ` ` ` ` ` `if` `(N > 0 && M > 0) ` ` ` `return` `N * M; ` ` ` `else` ` ` `return` `0; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `N = 5, M = 3, K = 2; ` ` ` ` ` `cout << remainingArea(N, M, K); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to return the area ` ` ` `// of the remaining plot ` ` ` `static` `int` `remainingArea(` `int` `N, ` `int` `M, ` `int` `K) ` ` ` `{ ` ` ` ` ` `// Continue while plot has positive area ` ` ` `// and there are persons left ` ` ` `while` `(K-- > ` `0` `&& N > ` `0` `&& M > ` `0` `) { ` ` ` ` ` `// If length > breadth ` ` ` `// then subtract breadth from length ` ` ` `if` `(N > M) ` ` ` `N = N - M; ` ` ` ` ` `// Else subtract length from breadth ` ` ` `else` ` ` `M = M - N; ` ` ` `} ` ` ` ` ` `if` `(N > ` `0` `&& M > ` `0` `) ` ` ` `return` `N * M; ` ` ` `else` ` ` `return` `0` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `N = ` `5` `, M = ` `3` `, K = ` `2` `; ` ` ` ` ` `System.out.println(remainingArea(N, M, K)); ` ` ` `} ` `} ` ` ` `/* This code contributed by PrinciRaj1992 */` |

*chevron_right*

*filter_none*

## Python3

# Python3 implementation of the approach

# Function to return the area

# of the remaining plot

def remainingArea(N, M, K):

# Continue while plot has positive area

# and there are persons left

while (K > 0 and N > 0 and M > 0):

# If length > breadth

# then subtract breadth from length

if (N > M):

N = N – M;

# Else subtract length from breadth

else:

M = M – N;

K = K – 1;

if (N > 0 and M > 0):

return N * M;

else:

return 0;

# Driver code

N = 5;

M = 3;

K = 2;

print(remainingArea(N, M, K));

# This code contributed by Rajput-Ji

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to return the area ` ` ` `// of the remaining plot ` ` ` `static` `int` `remainingArea(` `int` `N, ` `int` `M, ` `int` `K) ` ` ` `{ ` ` ` ` ` `// Continue while plot has positive area ` ` ` `// and there are persons left ` ` ` `while` `(K-- > 0 && N > 0 && M > 0) { ` ` ` ` ` `// If length > breadth ` ` ` `// then subtract breadth from length ` ` ` `if` `(N > M) ` ` ` `N = N - M; ` ` ` ` ` `// Else subtract length from breadth ` ` ` `else` ` ` `M = M - N; ` ` ` `} ` ` ` ` ` `if` `(N > 0 && M > 0) ` ` ` `return` `N * M; ` ` ` `else` ` ` `return` `0; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main() ` ` ` `{ ` ` ` `int` `N = 5, M = 3, K = 2; ` ` ` ` ` `Console.WriteLine(remainingArea(N, M, K)); ` ` ` `} ` `} ` ` ` `/* This code contributed by ajit */` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the area ` `// of the remaining plot ` `function` `remainingArea(` `$N` `, ` `$M` `, ` `$K` `) ` `{ ` ` ` ` ` `// Continue while plot has positive area ` ` ` `// and there are persons left ` ` ` `while` `(` `$K` `-- && ` `$N` `&& ` `$M` `) ` ` ` `{ ` ` ` ` ` `// If length > breadth ` ` ` `// then subtract breadth from length ` ` ` `if` `(` `$N` `> ` `$M` `) ` ` ` `$N` `= ` `$N` `- ` `$M` `; ` ` ` ` ` `// Else subtract length from breadth ` ` ` `else` ` ` `$M` `= ` `$M` `- ` `$N` `; ` ` ` `} ` ` ` ` ` `if` `(` `$N` `> 0 && ` `$M` `> 0) ` ` ` `return` `$N` `* ` `$M` `; ` ` ` `else` ` ` `return` `0; ` `} ` ` ` `// Driver code ` `$N` `= 5; ` `$M` `= 3; ` `$K` `= 2; ` ` ` `echo` `remainingArea(` `$N` `, ` `$M` `, ` `$K` `); ` ` ` `// This code is contributed by AnkitRai01 ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

## Recommended Posts:

- Element equal to the sum of all the remaining elements
- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Check if the array has an element which is equal to sum of all the remaining elements
- Delete odd and even numbers at alternate step such that sum of remaining elements is minimized
- Check if the array has an element which is equal to product of remaining elements
- Append a digit in the end to make the number equal to the length of the remaining string
- Minimum number of points to be removed to get remaining points on one side of axis
- Area of a Hexagon
- Area of a Regular Pentagram
- Program for Area Of Square
- Maximum area of quadrilateral
- Area of a Circular Sector
- Area of Reuleaux Triangle
- Sum of Area of all possible square inside a rectangle

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.