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
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 10^9).
Output
Write the needed number of flagstones.
Examples
Input
6 6 4
Output
4
题目要求
用边长为a的正方形砖,铺面积为m*n的广场。
要求:砖的面积可以稍微大一点,但是必须铺满广场,并且砖不能打碎。
输入m,n,a
输出所需最少的砖的数量。
解题思路
因为砖不能打碎,所以不能按照面积来算,所以求出每边长对应的最少的砖的数,再相乘。
先用if()判断两边都不能对应整数块砖,则都加一;
然后判断两边都能整除;
最后判断一边不能整除(长和宽两类情况分开);
输出对应结果;
代码如下
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
long long n, a, m;
cin >> n >> m >> a;
if(m%a!=0&&n%a!=0)
cout <<(( m / a)+1) *(( n / a) +1)<< endl;
else
if(m%a == 0 && n%a == 0)
cout <<( m / a )*( n / a) << endl;
else
if(m%a == 0 && n%a != 0)
cout <<(m / a) * ((n / a) +1)<< endl;
else
if (m%a != 0 && n%a == 0)
cout << ((m / a)+1) * (n / a ) << endl;
return 0;
}
继续阅读与本文标签相同的文章
高德地图
吴忌寒革职詹克团,强势回归被称“矿圈乔布斯”
-
阿里巴巴小程序繁星计划技术能力支持指南
2026-05-18栏目: 教程
-
Spring Cloud Alibaba实战(一) - 概述
2026-05-18栏目: 教程
-
php系列----->通过PHP数组实现队列
2026-05-18栏目: 教程
-
MySQL 数据库铁律
2026-05-18栏目: 教程
-
Java 13 明天发布,最新最全新特性解读
2026-05-18栏目: 教程
