- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find the number of rectangles of size 2x1 which can be placed inside a rectangle of size n x m in Python

Suppose we have two values n and m; we have to find the number of rectangles of size 2x1 that can be set inside a rectangle of size n x m. There are few conditions, that we have to consider −

Any two small rectangles cannot overlap.

Every small rectangle lies completely inside the bigger one. It is permitted to touch the edges of the bigger rectangle.

So, if the input is like

n = 3, m = 3, then the output will be 4

To solve this, we will follow these steps −

if n mod 2 is same as 0, then

return(n / 2) * m

otherwise when m mod 2 is 0, then

return(m / 2) * n

return (n * m - 1) / 2

## Example

Let us see the following implementation to get better understanding −

def count_rect(n, m): if (n % 2 == 0): return (n / 2) * m elif (m % 2 == 0): return (m // 2) * n return (n * m - 1) // 2 n = 3 m = 3 print(count_rect(n, m))

## Input:

3, 3

## Output

4

- Related Articles
- Count the number of ways to tile the floor of size n x m using 1 x m size tiles in C++
- Count the number of rhombi possible inside a rectangle of given size in C++
- Split String of Size N in Python
- Program to find latest group of size M using Python
- Find size of a list in Python
- Program to count number of palindromes of size k can be formed from the given string characters in Python
- Find a sorted subsequence of size 3 in linear time in Python\n
- Program to find number of increasing subsequences of size k in Python
- Program to find number of rectangles that can form the largest square in Python
- See the figure and find the ratio of(a) Number of triangles to the number of circles inside the rectangle.(b) Number of squares to all the figures inside the rectangle.(c) Number of circles to all the figures inside the rectangle."
- An object of size 7.0 cm is placed at 27 cm in front of a concave mirror of focal length 18 cm. At what distance from the mirror should a screen be placed so that a sharp focussed image can be obtained? Find the size and nature of image.
- Break a list into chunks of size N in Python
- Python program to Find the size of a Tuple
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- If the magnification of a body of size 1 m is 2, what is the size of the image?

Advertisements