hdu1097求幂的个位

想通了的话这道题目很easy。其实对这种什么取个位,取模一个很小的数的都应当想到打表。像这个题目就完全可以作为一个模版使用了。。

#include<iostream>
using namespace std;

const int tab[10][4]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
int main()
{
    int a,b;
    while(cin>>a>>b)//求a^b最末位
    {
        a=a%10;
        b=(b-1)%4;
        cout<<tab[a][b]<<endl;
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/cj695/p/2613506.html