Theatre Square-Codeforces rated 1000

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.


6 6 4




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.


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.




Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ActionCable/AnyCable with Angular 9

View Database Tables as Standard Java Streams Using Speedment

Tips and Tricks for Technical Interviews

JIRA project

The Technical QA test

WHAT ARE Threads in Java…!!!

Big O Notation, but it’s socks

colorful socks hanging from a drying rack by clothespins

Use Jupyter to Explore Your Cloud!

I made this 4K rendered image using a CAD tool with ray tracing

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Upskilling students for tech placements!

More from Medium

Minimum Number of Jumps

Goldman Sachs — SDE

Women Who Code Mentorship Program 4.0 - Week 2

Women Who Code Delhi

Longest Substring Without Repeating Characters