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.。

红果果的快速幂模板

转载于:https://www.cnblogs.com/greenaway07/p/11196956.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值