HDU Rightmost Digit
题意,求每个数n^n 的个位数是多少;
- 快速幂裸题qwq 相当于算出n^n 后对10取模
- 注意事项:
- 根据取模的性质:balabala反正一直模就对了√
- 自定义函数里刚开始 int qsm(ll x, ll y) 将long long 定义成了int , 和主函数里放进去的a的类型不一样qwq就WA了!注意哟qwq
代码君quq
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 #define ll long long 5 ll a,b,ans = 1; 6 int T; 7 int qsm(ll x, ll y) {//这里!! 8 ans = 1; 9 while(y>0) { 10 if(y&1) ans = ans*x%10; 11 x = x*x%10;//一直取模 12 y = y>>1; 13 } 14 return ans%10; 15 } 16 int main() { 17 scanf("%d",&T); 18 while(T--) { 19 scanf("%d",&a); 20 cout<<qsm(a,a)<<endl; 21 } 22 return 0; 23 }
bingo√