Theatre Square-Codeforces rated 1000

Placewit
2 min readJan 16, 2022

Problem Statement :

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 × 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.

Input Format:

The input contains three positive integer numbers in the first line: n, m, and a (1 ≤ n, m, a ≤ 10^9).

Output Format:

The output contains 1 line having the number of flagstones required.

Given:

6 6 4

Output:

4

Approach:

The constraint that edges of each flagstone much be parallel to edges of the square allows to analyze X and Y axes separately, that is, how many segments of length ‘a’ are needed to cover a segment of length ‘m’ and ’n’ — and take the product of these two quantities. Answer = ceil(m/a) * ceil(n/a), where ceil(x) is the least integer which is above or equal to x. Using integers only, it is usually written as ((m+a-1)/a)*((n+a-1)/a). Note that answer may be as large as 10¹⁸, which does not fit in a 32-bit integer.

Code:

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--