HDU1061 求n^n的最低位

因为0-9 的4次方的的末尾数为其本身,所以是以4为循环的,其代码为:

 #include<stdio.h>
int main()
{
int n,i,s,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s=1;
for(i=1;i<=(n%4+4);i++) //+4是因为当n为4的倍数时 n%4=0 就不执行循环了
{
s*=(n%10);
s=s%10;
}
printf("%d\n",s);
}

return 0;
}



 
自己的方法,仅供参考!
原文地址:https://www.cnblogs.com/hsqdboke/p/2384487.html