您的位置:首页 > 其它

hdu 1097 A hard puzzle

2015-09-17 16:51 381 查看

A hard puzzle

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


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
There are mutiple test cases. Each test cases consists
of two numbers a and b(0<a,b<=2^30)

[align=left]Output[/align]
For each test case, you should output the a^b's last
digit number.

[align=left]Sample Input[/align]

7 66
8 800

[align=left]Sample Output[/align]

9

6

[align=left]Author[/align]
eddy

[align=left]Recommend[/align]
JGShining | We have carefully selected several
similar problems for you: 1170 1164 1087 1032 1062

和以前做的一道题几乎一样,上一次是求N^N的个位数,这次是求a^b的个位数,不过过程其实是一样的。。

题意:求a^b的个位数。

附上代码:

#include <iostream>
using namespace std;
int s[5];
void add(int t)
{
int i,k=1;
for(i=1; i<=4; i++) //通过打表找规律,发现a^b的个位数字4个一循环,而且只需要保存个位数
{
k=k*t%10;
s[i]=k;
}
}
int main()
{
int a,b,i,k;
while(cin>>a>>b)
{
if(b==0)
{
cout<<1<<endl;
continue ;
}
a=a%10;
add(a);
k=b%4;
if(k==0)
cout<<s[4]<<endl;
else
cout<<s[k]<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: