hdu 1061 快速幂
求n^n的个位
Sample Input
2
3
4
Sample Output
7
6
直接快速幂了,注意要用long long
1 #include<cstdio> 2 long long quick_mod(long long a,long long b,long long m) { 3 long long ans = 1; 4 while (b) { 5 if (b&1) { 6 ans = (ans * a) % m; 7 b--; 8 } 9 b/=2; 10 a = a * a% m; 11 } 12 return ans; 13 } 14 int main() 15 { 16 int t,n; 17 scanf("%d",&t); 18 while(t--) 19 { 20 scanf("%d",&n); 21 printf("%lld\n",quick_mod(n,n,10)); 22 } 23 return 0; 24 }