> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/solutions/1240-tiling-a-rectangle-with-the-fewest-squares.md).

# 1240. Tiling a Rectangle with the Fewest Squares

<https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares>

## Description

Given a rectangle of size `n` x `m`, return *the minimum number of integer-sided squares that tile the rectangle*.

**Example 1:**

![](https://assets.leetcode.com/uploads/2019/10/17/sample_11_1592.png)

```
**Input:** n = 2, m = 3
**Output:** 3
**Explanation:** 3 squares are necessary to cover the rectangle.
2 (squares of 1x1)
1 (square of 2x2)
```

**Example 2:**

![](https://assets.leetcode.com/uploads/2019/10/17/sample_22_1592.png)

```
**Input:** n = 5, m = 8
**Output:** 5
```

**Example 3:**

![](https://assets.leetcode.com/uploads/2019/10/17/sample_33_1592.png)

```
**Input:** n = 11, m = 13
**Output:** 6
```

**Constraints:**

* `1 <= n, m <= 13`

## ac

```java
```
