Z 433 Parliament Square HackerRank Contest Question


Parliament in the capital city of Delhi 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 Parliament 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.
Constraints
1 ≤  n, m, a ≤ 10^9
Output Format
Write the needed number of flagstones.
Sample Input 0
6 6 4
Sample Output 0
4
SOurce COde:
#include <iostream>  
using namespace std;  
int main()  
{  
 long long int n,m,a,ans;  
 while(cin>>n>>m>>a){  
     if(a>n and a>m) cout<<"1"<<endl;  
    else{  
   if(n%a>0) n = (n/a)+1;  
    else n = (n/a);  
    




     if(m%a>0) m = (m/a)+1;  
     else m = (m/a);  
     ans = n*m;  
      cout<<ans<<endl;  
    }  
   }  
    return 0;  
 }  

Comments