题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061

刚刚在百度学的快速幂,学自这里:http://wenku.baidu.com/view/2384ecc02cc58bd63186bdf6.html

#include <iostream>
using namespace std;
int ans;
int QwickPowerMod(int a,int b,int c)
{
    int ans=1;
    a=a%c;
    while(b>0)
    {
        if(b%2==1)
        ans=ans*a%c;
        b=b/2;
        a=a*a%c;
    }
    return ans;
}
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<QwickPowerMod(n,n,10)<<endl;
    }
}