传送门:HDU 1097
题意
求a ^ b % 10
题解
快速幂取模
/*
adrui's submission
Language : C++
Result : Accepted
Love : ll
Favorite : Dragon Balls
Standing in the Hall of Fame
*/
#include<cstdio>
#include<cstring>
using namespace std;
#define debug 0
int a, b;
int fast_pow_mod() {
int res = 1;
while(b){
if (b & 1) res = res * a % 10;
a = a * a % 10;
b >>= 1;
}
return res;
}
int main() {
#if debug
freopen("in.txt", "r", stdin);
#endif //debug
while (~scanf("%d%d", &a, &b)) {
a %= 10; //预处理先模10
printf("%d\n", fast_pow_mod());
}
return 0;
}