A hard puzzleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 52469 Accepted Submission(s): 19190 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.
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
Author eddy |
解题的思路主要是找规律,发现所有数的n次幂的个位数都是有一定规律的:个位上的数是以4为周期交替出现的。
AC代码:
#include<stdio.h>
int main()
{
int a,b,m;
while(scanf("%d%d",&a,&b) != EOF)
{
a %= 10;
b %= 4;
b = b?b:4;
m = 1;
for(int i=0;i<b;i++)
m = m*a;
printf("%d\n",m%10);
}
return 0;
}