Description
Input
Output
Sample Input
Sample Output
Hint
Description
Theatre Square in the capital city of Berland has a rectangular shape with the sizen × 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 sizea × 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 anda (1 ≤ n, m, a ≤ 109).
Output
Write the needed number of flagstones.
Sample Input
6 6 4
4
#include<iostream>
using namespace std;
long long fun(long long y,long long x){
if(y%x==0)
return y/x;
else
return 1+y/x;
}
int main(){
long long n,m,a;
while(cin>>n>>m>>a){
cout<<fun(n,a)*fun(m,a)<<endl;
}
return 0;
}
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
Sample Input
2 3 4
Sample Output
7 6
Hint
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
#include<iostream>
#include<math.h>
using namespace std;
int X[10][5];
int main(){
int r,t,N;
for(int i=0;i<10;i++)
for(int j=1;j<=4;j++){
r=(int)pow(i,j);
X[i][j]=r%10;
}
for(int i=0;i<10;i++){
X[i][0]=X[i][4];
}
cin>>t;
while(t--){
cin>>N;
r=N%10;
cout<<X[r][N%4]<<endl;
}
return 0;
}
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Output
输出n行,每行是对应的位置的转化结果。
Sample Input
Sample Output
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int get_ascii(char c){
if(c>=65&&c<=90)
return c-64;
else if(c>=48&&c<=57){
return c-48;
}
}
char get_char(int n){
if(n>0)
return (char)(64+n);
else
return 'Z';
}
void to_r_c_r_c(string st){
char str[20];
int r=0,l=0,i;
i=0;
for(i=0;i<st.size();i++){
str[i]=st[i];
}
i=0;
for(;str[i]>=65;i++){
r=r*26;
r=r+get_ascii(str[i]);
}
for(;i<st.size();i++){
l=l*10;
l=l+get_ascii(str[i]);
}
cout<<"R"<<l<<"C"<<r<<endl;
}
void to_string(int n){
int i=0,j=0;
char c[5];
for(;n>=1;i++){
c[i]=get_char((n-1)%26+1);
n=(n-1)/26;
}
for(j=i-1;j>=0;j--){
cout<<c[j];
}
}
void to_b_c(string st){
char str[20];
int r=0,l,i;
for(i=0;i<st.size();i++){
str[i]=st[i];
}
r=0;
i=1;
for(;str[i]<=57;i++){
//cout<<"<";
r=r*10;
r=r+get_ascii(str[i]);
}
l=r;
r=0;
for(i=i+1;i<st.size();i++){
r=r*10;
r=r+get_ascii(str[i]);
}
to_string(r);
cout<<l;
cout<<endl;
}
int main(){
int t;
string s;
cin>>t;
while(t--){
cin>>s;
if((int)s[0]=='R'&&(int)s[1]<=57&&s.find('C')!=-1)
to_b_c(s);
else
to_r_c_r_c(s);
}
return 0;
}
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Each player chooses two numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of all expressions Ai Bi from all players including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.
You should write a program that calculates the result and is able to find out who won the game.
Input
Output
(A1B1+A2B2+ ... +AHBH)mod M.
Sample Input
3 16 4 2 3 3 4 4 5 5 6 36123 1 2374859 3029382 17 1 3 18132
Sample Output
2 13195 13
#include<iostream>
#include<math.h>
using namespace std;
#define N 45010
int AB[N][2];
int bin(int A,int B,int M){
int n,a,c;
a=A%M;
c=1;
n=B;
if(A==0&&B!=0)
return 0;
else if(A!=0&&B==0)
return 1;
else if(A==1)
return 1;
for(;n>=1;){
a=a%M;
c=c%M;
if(n%2==1){
c=c*a;
c=c%M;
n=n/2;
a=a*a;
a=a%M;
}
else{
c=c;
c=c%M;
n=n/2;
a=a*a;
a=a%M;
}
}
return c;
}
int main(){
int t,M,H,result;
cin>>t;
while(t--){
result=0;
cin>>M>>H;
for(int i=0;i<H;i++){
cin>>AB[i][0]>>AB[i][1];
result=result+bin(AB[i][0],AB[i][1],M);
}
result=result%M;
cout<<result<<endl;
}
return 0;
}