N^N的最右边的数
方法一:找规律
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int t,n,ans;
cin>>t;
while(t--)
{
cin>>n;
int tmp=n%10;
if(tmp==0 || tmp==1||tmp==5 ||tmp==6)
{
ans=tmp;
}
else if(tmp==2 || tmp==3||tmp==7||tmp==8)
{
if(n%4==0)
ans=(int)pow(tmp,4)%10;
else
ans=(int)pow(tmp,(n%4))%10;
}
else
{
if(n%2==0)
ans=(int)pow(tmp,2)%10;
else
ans=(int)pow(tmp,(n%2))%10;
}
cout<<ans<<endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int quick_mod(int a,int m)
{
int b=1;
while(m>0)
{
if(m&1)
{
b=b*a%10;
}
m>>=1;
a=a*a%10;
}
return b;
}
int main()
{
int t,n,ans;
cin>>t;
while(t--)
{
cin>>n;
int tmp=n%10;
ans=quick_mod(tmp,n);
cout<<ans<<endl;
}
return 0;
}