给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Sample Input
13
Sample Output
3
#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
ll power(ll a,ll b)
{
ll ans = 1;
a = a%10;
while(b>0)
{
if(b%2==1)
ans = (ans*a)%10;
b/=2;
a = (a*a)%10;
}
return ans;
}
int main(){
ll a;
cin>>a;
ll b = power(a,a);
cout<<b%10;
}