[51NOD] 1004 n^n的末位数字
给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Sample Input
13
Sample Output
3
只需拿出末尾数字进行快速幂即可。
题解:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int quickpow(int a,int b){
int res=1;
while(b){
if(b&1) res=res*a%10;
a=a*a%10;
b>>=1;
}
return res;
}
int main(){
int n;
scanf("%d",&n);
int m=n%10;
int ans=quickpow(m,n);
printf("%d\n",ans);
return 0;
}