# Can somebody elaborate the maths behind this problem?

Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size $$a \times a$$.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Note: $$a$$, $$n$$ and $$m$$ are integers and the final answer should also be an integer.

Say that $$n$$ and $$m$$ are both $$6$$ and $$a$$ is $$4$$. Then the minimum no should be $$4$$.

• Is $a$ an integer number? – Berci Mar 20 at 13:22
• Edited the question! – RaphX Mar 20 at 13:24
• Maybe you can consider the two dimensions separately, if the stones are laid in a rectangular grid. So you can ask: What is the smallest multiple of $a$ that's $\geq n$ ? And the same for $m$ ... – Matti P. Mar 20 at 13:27
• The problem statement says "It's allowed to cover the surface larger than the Theatre Square". So what disallows a solution with one giant square flagstone with sides $\ge \max(m,n)$ ? – gandalf61 Mar 20 at 13:50
• For equations, please use MathJax. – dantopa Mar 21 at 0:56

## 1 Answer

We can without loss generality dub n the height of the rectangle and m the width.

The total number of flagstones is equal to the number of flagstones needed to cover the width of theatre square times the number of flagstones needed to cover the height.

The number of flagstones that are needed to cover the height is equal to the height n divided by the height of a flagstone a, but if n is not divisible by a then that number is some fraction, but we still need to cover the same area as that fraction of a flagstone does, the solution the next integer higher than $$\frac{n}a$$, the ceiling function.

As the same thing holds for theatre squares width m, the total number of flagstones must be

$$\lceil\frac{n}a\rceil\times\lceil\frac{m}a\rceil$$