标签:os io amp htm sp c return algorithm
//模幂运算,而且求个位,一直求10的模
# include <stdio.h>
# include <algorithm>
# include <math.h>
using namespace std;
__int64 Pow(__int64 m,__int64 n)
{
__int64 p=1;
while(n)
{
if(n%2)
p=p*m%10;
n/=2;
m=m*m%10;
}
return p%10;
}
int main()
{
int t;
__int64 n,m;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%I64d",&n);
m=n;
m%=10;//求个位的n次取模
if(m==0)
printf("0\n");
else
printf("%I64d\n",Pow(m,n));
}
}
return 0;
}
hdu 1061 Rightmost Digit,布布扣,bubuko.com
标签:os io amp htm sp c return algorithm
原文地址:http://blog.csdn.net/lp_opai/article/details/38708241