

给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Input示例
13
Output示例
3
【代码】:


#include <bits/stdc++.h> using namespace std; #define LL long long LL n; int main() { while(~scanf("%lld",&n)) { LL ans=1,tmp=n;//改变位数,所以要临时变量 while(n) { if(n&1) { ans=ans*tmp%10; } tmp=tmp*tmp%10;//改变位数的地方用临时变量 n>>=1; } printf("%lld\n",ans); } return 0; }