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.

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.

--

--

--

Upskilling students for tech placements!

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

Recommended from Medium

Python and pandas functionality ‘slowdowns’

Linking In and Connecting to Build A Network of Skillsets

Understand Enumerable and Enumerators

Autocomplete and Suggestions with the Search API

A 5-Step Approach To Integrate Real-Time Broadcasting In Laravel

A 5-Step Approach To Integrate Real-Time Broadcasting In Laravel

Paxos, Raft, EPaxos: How Has Distributed Consensus Technology Evolved?

Making a VM Use Host’s VPN Connection

The Blind 75 Leetcode Series: Valid Parentheses

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
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Color of Next Ball Puzzle

Find the K-Beauty of a Number

Interview Questions For Developers To Ask Potential Employers

Dan Bunting — Game Developer