764人阅读 评论(0)

# A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16669    Accepted Submission(s): 5936

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

AC code：

#include <iostream>
using namespace std;
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
a%=10;
if(a==0||a==5||a==6||a==1) printf("%d\n",a);
else if(a==4||a==9)
{
printf("%d\n",b%2==0?a*a%10:a);
}
else
{
if(b%4==1) printf("%d\n",a);
else if(b%4==2) printf("%d\n",a*a%10);
else if(b%4==3) printf("%d\n",a*a*a%10);
else printf("%d\n",a*a*a*a%10);
}
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：503565次
• 积分：5629
• 等级：
• 排名：第4796名
• 原创：187篇
• 转载：14篇
• 译文：0篇
• 评论：21条
最新评论