hdu 1061 Rightmost Digit

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 #include <iomanip>
15  #include <fstream>
16 using namespace std;
17 typedef long long ll;
18 const int maxn=1000009;
19 
20 
21 ll qpow(ll a,ll b)
22 {
23     ll ans=1,base=a;
24     while(b>0)
25     {
26         if(b&1)
27         {
28             ans*=base;
29             ans%=10;
30         }
31         base*=base;
32         base%=10;
33         b>>=1;
34     }
35     return ans;
36 }
37 int main()
38 {
39     ll n;
40     int t;
41     scanf("%d",&t);
42     while(t--)
43     {
44         scanf("%I64d",&n);
45         ll ans;
46         ans=qpow(n,n);
47         printf("%I64d\n",ans);
48     }
49 
50     return 0;
51 }
View Code

我一开始还很虚,最后一位(个位)怎么求。。。以为没有那么简单粗暴地搞个mod 10.。

红果果的快速幂模板

posted @ 2019-07-16 19:22  鹤花之歌  阅读(166)  评论(0编辑  收藏  举报