题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097
题目大意:给出a, b 两个数,要求输出pow(a, b)%10 (0<a,b<=2^30)
分析://。。。利用快速幂运算。。。还没想好怎么才能把快速幂运算讲清楚(留着以后填坑)
ac代码
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll pow_fast(ll a, ll b)
{
ll res = 1;
while(b > 0)
{
if(b & 1)res = res * a % 10;
a = a * a % 10;
b = b >> 1;
}
return res;
}
int main()
{
ll a, b;
while(scanf("%lld %lld", &a, &b) != EOF)
{
ll res = pow_fast(a, b);
printf("%d\n", res % 10);
}
return 0;
}