Time limit: 1000 ms
Memory limit: 262144 kB
Source :Codeforces Beta Round #1
Tags: math *1300
Editorial: Announcement Tutorial #1 Tutorial #2
Problem Description:
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.
Sample Input
6 6 4
Sample Output
4
问题链接:https://vjudge.net/contest/275894#problem
问题简述:输入三个整数,其中前两个代表一个长方形的长和宽,第三个代表一个正方形的边长,计算该长方形应该由几个正方形构成
问题分析:应当注意的是,正方形不能拆分;并且,三个边长均有范围,且范围较大,即使用高精度整数型为正确
程序说明:该程序使用高精度整数型扩大整数范围,实现直接输入与输出;
AC通过的程序如下:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long long int n,m,a;
cin>>n>>m>>a;
if(n<1 || n>pow(10.0, 9.0) || m<1 || m>pow(10.0, 9.0) || a<1 || a>pow(10.0, 9.0))
return 0;
else
{
if(n%a==0&&m%a==0)
cout<<n/a*(m/a);
else if(n%a==0&&m%a!=0)
cout<<n/a*(m/a+1);
else if(n%a!=0&&m%a==0)
cout<<(n/a+1)*(m/a);
else
cout<<(n/a+1)*(m/a+1);
}
}