`

ACM题:a hard puzzle 求数a的b(可以很大)次方的最低位

    博客分类:
  • ACM
 
阅读更多
A hard puzzle
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5314    Accepted Submission(s): 1832


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

simple c code:
#include <stdio.h>
int main()
{
unsigned long a,b,i,temp,k,t,start;
while(scanf("%d%d",&a,&b)!=EOF)
{
temp=1;
a=a%10;
    start=a;t=1;k=a*a%10;
        while(k!=start)
{
t++;
k=k*a%10;
}
//printf("%d\n",t);
    b=b%t;
if(b==0)
b=t;
for(i=1;i<=b;i++)
{
temp=temp*a%10;
// printf("%ld  ",temp);
}
printf("%ld\n",temp);
}
return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics