description
A ^ B integer seek the last three digits of the (1 <= A, B <= 1000)
Entry
The first line of the input integer n, there are n represents a test case, then there are n rows, each row one example, given two positive integers A, B
Export
For each test case, the output of the last three of A ^ B (without a leading 0), a separate line.
Sample input Copy
2
2 3
12 6
Sample output Copy
8
984
topics as
the following look at my final answer:
#include<stdio.h>
int p(int x,int y)
{
int i,num=1;
for(i=0;i<y;i++)
{
num*=x;
num=num%1000;
}
return num;
}
int main()
{
int x,y,n;
int date;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&x,&y);
date=p(x,y);
printf("%d\n",date);
}
return 0;
}
Generally the problem is to use the pow () function call <math.h>
In fact, questions and issues before the factorial of similar
Data overflow problem
This is the beginning of my ideas:
#include<stdio.h>
#include<math.h>
int main()
{
int n,i;
scanf("%d",&n);
for(i=n;i>0;i--)
{
int x,y,date;
scanf("%d%d",&x,&y);
date=pow(x,y);
printf("%d\n",date%1000);
}
return 0;
}
Did not think so much, but I ignored the problem of data overflow, so we can not use this question * pow () function, to avoid data overflow, then it can not calculate the results (I can only think this way) but to ensure that the result is correct ---------->
for(i=0;i<y;i++)
{
num*=x;
num=num%1000;
}
After leaving only a few can
Here there are several use pow () function needs to pay attention to the problem of
using pow () function problems need to pay attention
if it helps their own, then please leave a readily praise Caesar> - <