hdu 1097 A hard puzzle

时间:2023-03-09 15:13:50
hdu 1097  A hard puzzle
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output
For each test case, you should output the a^b's last digit number.
Sample Input
7 66
8 800
Sample Output
9
6
题目意思就是求给定两数的次方,然后取最后一位;
我的想法:决定最后一位的只有最后一位数,所以首先对求a对10求余的数值并赋给a,其次通过找规律得到,每4次一循环,所以求b对4求余的数值并赋给b;接下来应该都懂了,代码如下;
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d;
while(scanf("%d%d",&a,&b)!=EOF)
{
a=a%;b=b%;
if(b==)
b=;
c=pow(a,b);
d=c%;
printf("%d\n",d);
} }