题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097
题目大意:求n^p的末尾数
关键思想:循环节,与HDU1005思想类似http://www.cnblogs.com/G-M-WuJieMatrix/p/6407740.html,更简单
代码如下:
//循环节
#include <iostream>
using namespace std;
typedef long long ll;
int mod[102]; //其实大小为10的数组就够了
int main(){
ll n,p;
while(cin>>n>>p){
mod[0]=1,mod[1]=n%10;
int i;
for(i=2;;i++){
mod[i]=n*mod[i-1]%10;
if(mod[i]==mod[1])break;
}
cout<<mod[p%(i-1)==0?i-1:p%(i-1)]<<endl;
}
return 0;
}