您的位置:首页 > 其它

HDU1061 Rightmost Digit

2013-04-04 18:57 417 查看
题意:

求N^N的最右位数字

快速幂解决

#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int total;
scanf("%d",&total);
while(total--)
{
int n;
scanf("%d",&n);
int m=n;//n^m
int ans=1;
n%=10;
while(m)
{
if(m&1)//m为奇数
{
ans*=n;
ans%=10;
}
m>>=1;
n*=n;
n%=10;
}
printf("%d\n",ans%10);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: