求n^n最右边的一位

找出规律即可

View Code
#include<iostream>
using namespace std;

int main()
{
    int T,n,ans,t;
    cin>>T;
    while(T--)
    {
        cin>>n;
        t=n%10;
        n=(n-1)%4+1;
        for(ans=1;n--;ans*=t);
        cout<<ans%10<<endl;
    }
    return 0;
}
posted on 2012-04-30 11:11  pcoda  阅读(148)  评论(0编辑  收藏  举报